public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fortran: improve error recovery while simplifying size of bad array [PR103694]
@ 2022-08-23 20:29 Harald Anlauf
  2022-08-24 17:54 ` Tobias Burnus
  0 siblings, 1 reply; 3+ messages in thread
From: Harald Anlauf @ 2022-08-23 20:29 UTC (permalink / raw)
  To: fortran, gcc-patches

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

Dear all,

the simplification of the size of an array with a bad decl
should not be successful.  Improve the error recovery for
such a situation.

The patch is nearly obvious.  I therefore intend to commit
it in the next few days unless someone comes up with a
better solution.

Regtested on x86_64-pc-linux-gnu.

The PR is marked as a 12/13 regression.  Will therefore
commit to both.

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-improve-error-recovery-while-simplifying-siz.patch --]
[-- Type: text/x-patch, Size: 1832 bytes --]

From d306c0b171e502e3c87b92b6bc63b532f734e754 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Tue, 23 Aug 2022 22:16:14 +0200
Subject: [PATCH] Fortran: improve error recovery while simplifying size of bad
 array [PR103694]

gcc/fortran/ChangeLog:

	PR fortran/103694
	* simplify.cc (simplify_size): The size expression of an array cannot
	be simplified if an error occurs while resolving the array spec.

gcc/testsuite/ChangeLog:

	PR fortran/103694
	* gfortran.dg/pr103694.f90: New test.
---
 gcc/fortran/simplify.cc                |  5 +++--
 gcc/testsuite/gfortran.dg/pr103694.f90 | 11 +++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr103694.f90

diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc
index f992c31e5d7..bc178d54891 100644
--- a/gcc/fortran/simplify.cc
+++ b/gcc/fortran/simplify.cc
@@ -7536,8 +7536,9 @@ simplify_size (gfc_expr *array, gfc_expr *dim, int k)
     }

   for (ref = array->ref; ref; ref = ref->next)
-    if (ref->type == REF_ARRAY && ref->u.ar.as)
-      gfc_resolve_array_spec (ref->u.ar.as, 0);
+    if (ref->type == REF_ARRAY && ref->u.ar.as
+	&& !gfc_resolve_array_spec (ref->u.ar.as, 0))
+      return NULL;

   if (dim == NULL)
     {
diff --git a/gcc/testsuite/gfortran.dg/pr103694.f90 b/gcc/testsuite/gfortran.dg/pr103694.f90
new file mode 100644
index 00000000000..3ed8b2088da
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr103694.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR fortran/103694 - ICE in gfc_conv_expr_op
+! Contributed by G.Steinmetz
+
+subroutine s
+  type t
+     integer :: a(2)
+  end type
+  type(t) :: x((0.)/0)
+  integer :: n = size(x(1)%a) ! { dg-error "does not reduce to a constant expression" }
+end
--
2.35.3


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fortran: improve error recovery while simplifying size of bad array [PR103694]
  2022-08-23 20:29 [PATCH] Fortran: improve error recovery while simplifying size of bad array [PR103694] Harald Anlauf
@ 2022-08-24 17:54 ` Tobias Burnus
  2022-08-24 17:54   ` Tobias Burnus
  0 siblings, 1 reply; 3+ messages in thread
From: Tobias Burnus @ 2022-08-24 17:54 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches

Dear Harald,

On 23.08.22 22:29, Harald Anlauf via Fortran wrote:

the simplification of the size of an array with a bad decl
should not be successful.  Improve the error recovery for
such a situation.

[...]

Regtested on x86_64-pc-linux-gnu.
The PR is marked as a 12/13 regression.  Will therefore
commit to both.


LGTM – and thanks for taking care of the Fortran bugs!

Tobias

[PATCH] Fortran: improve error recovery while simplifying size of bad array [PR103694]

gcc/fortran/ChangeLog:

        PR fortran/103694
        * simplify.cc (simplify_size): The size expression of an array cannot
        be simplified if an error occurs while resolving the array spec.

gcc/testsuite/ChangeLog:

        PR fortran/103694
        * gfortran.dg/pr103694.f90: New test.
---
 gcc/fortran/simplify.cc                |  5 +++--
 gcc/testsuite/gfortran.dg/pr103694.f90 | 11 +++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr103694.f90

diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc
index f992c31e5d7..bc178d54891 100644
--- a/gcc/fortran/simplify.cc
+++ b/gcc/fortran/simplify.cc
@@ -7536,8 +7536,9 @@ simplify_size (gfc_expr *array, gfc_expr *dim, int k)
     }

   for (ref = array->ref; ref; ref = ref->next)
-    if (ref->type == REF_ARRAY && ref->u.ar.as)
-      gfc_resolve_array_spec (ref->u.ar.as, 0);
+    if (ref->type == REF_ARRAY && ref->u.ar.as
+       && !gfc_resolve_array_spec (ref->u.ar.as, 0))
+      return NULL;

   if (dim == NULL)
     {
diff --git a/gcc/testsuite/gfortran.dg/pr103694.f90 b/gcc/testsuite/gfortran.dg/pr103694.f90
new file mode 100644
index 00000000000..3ed8b2088da
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr103694.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR fortran/103694 - ICE in gfc_conv_expr_op
+! Contributed by G.Steinmetz
+
+subroutine s
+  type t
+     integer :: a(2)
+  end type
+  type(t) :: x((0.)/0)
+  integer :: n = size(x(1)%a) ! { dg-error "does not reduce to a constant expression" }
+end


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fortran: improve error recovery while simplifying size of bad array [PR103694]
  2022-08-24 17:54 ` Tobias Burnus
@ 2022-08-24 17:54   ` Tobias Burnus
  0 siblings, 0 replies; 3+ messages in thread
From: Tobias Burnus @ 2022-08-24 17:54 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches

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

Dear Harald,

On 23.08.22 22:29, Harald Anlauf via Fortran wrote:

the simplification of the size of an array with a bad decl
should not be successful.  Improve the error recovery for
such a situation.

[...]

Regtested on x86_64-pc-linux-gnu.
The PR is marked as a 12/13 regression.  Will therefore
commit to both.


LGTM – and thanks for taking care of the Fortran bugs!

Tobias

[PATCH] Fortran: improve error recovery while simplifying size of bad array [PR103694]

gcc/fortran/ChangeLog:

        PR fortran/103694
        * simplify.cc (simplify_size): The size expression of an array cannot
        be simplified if an error occurs while resolving the array spec.

gcc/testsuite/ChangeLog:

        PR fortran/103694
        * gfortran.dg/pr103694.f90: New test.
---
 gcc/fortran/simplify.cc                |  5 +++--
 gcc/testsuite/gfortran.dg/pr103694.f90 | 11 +++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr103694.f90

diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc
index f992c31e5d7..bc178d54891 100644
--- a/gcc/fortran/simplify.cc
+++ b/gcc/fortran/simplify.cc
@@ -7536,8 +7536,9 @@ simplify_size (gfc_expr *array, gfc_expr *dim, int k)
     }

   for (ref = array->ref; ref; ref = ref->next)
-    if (ref->type == REF_ARRAY && ref->u.ar.as)
-      gfc_resolve_array_spec (ref->u.ar.as, 0);
+    if (ref->type == REF_ARRAY && ref->u.ar.as
+       && !gfc_resolve_array_spec (ref->u.ar.as, 0))
+      return NULL;

   if (dim == NULL)
     {
diff --git a/gcc/testsuite/gfortran.dg/pr103694.f90 b/gcc/testsuite/gfortran.dg/pr103694.f90
new file mode 100644
index 00000000000..3ed8b2088da
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr103694.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR fortran/103694 - ICE in gfc_conv_expr_op
+! Contributed by G.Steinmetz
+
+subroutine s
+  type t
+     integer :: a(2)
+  end type
+  type(t) :: x((0.)/0)
+  integer :: n = size(x(1)%a) ! { dg-error "does not reduce to a constant expression" }
+end


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-24 17:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-23 20:29 [PATCH] Fortran: improve error recovery while simplifying size of bad array [PR103694] Harald Anlauf
2022-08-24 17:54 ` Tobias Burnus
2022-08-24 17:54   ` Tobias Burnus

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).