public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/103392 - [9/10/11/12 Regression] ICE in simplify_bound, at fortran/simplify.c:4273
@ 2021-11-23 20:46 Harald Anlauf
  2021-11-23 20:59 ` Mikael Morin
  0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2021-11-23 20:46 UTC (permalink / raw)
  To: fortran, gcc-patches

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

Dear all,

in simplify_bound we did hit an assert when trying to simplify
LBOUND/UBOUND for arrays with allocatable or pointer attribute.

We cannot do that.  Terminate simplification in that situation.

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-do-not-attempt-simplification-of-LU-BOUND-fo.patch --]
[-- Type: text/x-patch, Size: 2313 bytes --]

From 82c5d7ab299ad4bce98b53cc9bba223c29b34e66 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Tue, 23 Nov 2021 21:39:36 +0100
Subject: [PATCH] Fortran: do not attempt simplification of [LU]BOUND for
 pointer/allocatable

gcc/fortran/ChangeLog:

	PR fortran/103392
	* simplify.c (simplify_bound): Do not try to simplify
	LBOUND/UBOUND for arrays with POINTER or ALLOCATABLE attribute.

gcc/testsuite/ChangeLog:

	PR fortran/103392
	* gfortran.dg/bound_simplification_7.f90: New test.
---
 gcc/fortran/simplify.c                         |  6 ++++++
 .../gfortran.dg/bound_simplification_7.f90     | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/bound_simplification_7.f90

diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 6a6b3fbd037..c9e13b59da9 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -4266,6 +4266,12 @@ simplify_bound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind, int upper)
 	     || (as->type == AS_ASSUMED_SHAPE && upper)))
     return NULL;

+  /* 'array' shall not be an unallocated allocatable variable or a pointer that
+     is not associated.  */
+  if (array->expr_type == EXPR_VARIABLE
+      && (gfc_expr_attr (array).allocatable || gfc_expr_attr (array).pointer))
+    return NULL;
+
   gcc_assert (!as
 	      || (as->type != AS_DEFERRED
 		  && array->expr_type == EXPR_VARIABLE
diff --git a/gcc/testsuite/gfortran.dg/bound_simplification_7.f90 b/gcc/testsuite/gfortran.dg/bound_simplification_7.f90
new file mode 100644
index 00000000000..3efecdff769
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/bound_simplification_7.f90
@@ -0,0 +1,18 @@
+! { dg-do compile }
+! PR fortran/103392 - ICE in simplify_bound
+
+program p
+  integer, allocatable :: a(1:1) ! { dg-error "deferred shape or assumed rank" }
+  integer :: b(1) = lbound(a)    ! { dg-error "does not reduce" }
+  integer :: c(1) = ubound(a)    ! { dg-error "does not reduce" }
+end
+
+subroutine s(x, y)
+  type t
+     integer :: i(3)
+  end type t
+  type(t), pointer     :: x(:)
+  type(t), allocatable :: y(:)
+  integer, parameter   :: m(1) = ubound (x(1)% i)
+  integer              :: n(1) = ubound (y(1)% i)
+end subroutine s
--
2.26.2


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

* Re: [PATCH] PR fortran/103392 - [9/10/11/12 Regression] ICE in simplify_bound, at fortran/simplify.c:4273
  2021-11-23 20:46 [PATCH] PR fortran/103392 - [9/10/11/12 Regression] ICE in simplify_bound, at fortran/simplify.c:4273 Harald Anlauf
@ 2021-11-23 20:59 ` Mikael Morin
  0 siblings, 0 replies; 2+ messages in thread
From: Mikael Morin @ 2021-11-23 20:59 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches

Le 23/11/2021 à 21:46, Harald Anlauf via Fortran a écrit :
> Dear all,
> 
> in simplify_bound we did hit an assert when trying to simplify
> LBOUND/UBOUND for arrays with allocatable or pointer attribute.
> 
> We cannot do that.  Terminate simplification in that situation.
> 
> Regtested on x86_64-pc-linux-gnu.  OK for mainline/affected branches?
> 
OK. Thanks.

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

end of thread, other threads:[~2021-11-23 20:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-23 20:46 [PATCH] PR fortran/103392 - [9/10/11/12 Regression] ICE in simplify_bound, at fortran/simplify.c:4273 Harald Anlauf
2021-11-23 20:59 ` Mikael Morin

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