public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/103692 - [11/12 Regression] ICE in add_init_expr_to_sym, at fortran/decl.c:2062
@ 2022-01-17 21:58 Harald Anlauf
  2022-01-17 22:24 ` Thomas Koenig
  0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2022-01-17 21:58 UTC (permalink / raw)
  To: fortran, gcc-patches

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

Dear Fortranners,

after lengthy debugging of this PR it became obvious that we killed
the typespec while trying to expand an empty array constructor.

Bad idea, but easy to fix.

Regtested on x86_64-pc-linux-gnu.  OK for mainline and 11-branch?

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-handle-expansion-of-zero-sized-array-constru.patch --]
[-- Type: text/x-patch, Size: 3252 bytes --]

From b9be44b422063c6c1f7a4bb50245ba4051e76136 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Mon, 17 Jan 2022 22:52:08 +0100
Subject: [PATCH] Fortran: handle expansion of zero-sized array constructors

gcc/fortran/ChangeLog:

	PR fortran/103692
	* array.c (gfc_expand_constructor): Handle zero-sized array
	constructors.

gcc/testsuite/ChangeLog:

	PR fortran/103692
	* gfortran.dg/pr102520.f90: Adjust error messages.
	* gfortran.dg/pr103692.f90: New test.
---
 gcc/fortran/array.c                    |  3 +++
 gcc/testsuite/gfortran.dg/pr102520.f90 |  6 ++----
 gcc/testsuite/gfortran.dg/pr103692.f90 | 23 +++++++++++++++++++++++
 3 files changed, 28 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr103692.f90

diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c
index 472304326e8..f1d92e00c98 100644
--- a/gcc/fortran/array.c
+++ b/gcc/fortran/array.c
@@ -1883,6 +1883,9 @@ gfc_expand_constructor (gfc_expr *e, bool fatal)
   gfc_expr *f;
   bool rc;

+  if (gfc_is_size_zero_array (e))
+    return true;
+
   /* If we can successfully get an array element at the max array size then
      the array is too big to expand, so we just return.  */
   f = gfc_get_array_element (e, flag_max_array_constructor);
diff --git a/gcc/testsuite/gfortran.dg/pr102520.f90 b/gcc/testsuite/gfortran.dg/pr102520.f90
index 1c98c185c17..d2ea8f3a424 100644
--- a/gcc/testsuite/gfortran.dg/pr102520.f90
+++ b/gcc/testsuite/gfortran.dg/pr102520.f90
@@ -5,8 +5,6 @@ program p
   type t
   end type
   type(t), parameter :: a(4)   = shape(1)         ! { dg-error "Incompatible" }
-  type(t), parameter :: b(2,2) = reshape(a,[2,2]) ! { dg-error "Incompatible" }
-  type(t), parameter :: c(2,2) = transpose(b)     ! { dg-error "Unclassifiable" }
+  type(t), parameter :: b(2,2) = reshape(a,[2,2]) ! { dg-error "must be an array" }
+  type(t), parameter :: c(2,2) = transpose(b)     ! { dg-error "must be of rank 2" }
 end
-
-! { dg-error "Different shape for array assignment" " " { target *-*-* } 7 }
diff --git a/gcc/testsuite/gfortran.dg/pr103692.f90 b/gcc/testsuite/gfortran.dg/pr103692.f90
new file mode 100644
index 00000000000..9687a3cec9d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr103692.f90
@@ -0,0 +1,23 @@
+! { dg-do compile }
+! { dg-options "-fdump-tree-original" }
+! PR fortran/103692 - ICE in expand_constructor
+! Contributed by G.Steinmetz
+
+program p
+  character(3), parameter :: a(4) = 'abc'
+  character(*), parameter :: b(*) =  (a(2:1))
+  character(*), parameter :: y(*) = [(a(2:1))]
+  character(*), parameter :: u(*) =  a(2:1)
+  character(*), parameter :: v(*) = [a(2:1)]
+  character(*), parameter :: w(-1) = (a(2:1))
+  character(*), parameter :: x(-1) =  a(2:1)
+  character(5), parameter :: c(3,3) = 'def'
+  character(*), parameter :: d(*)   = [(c(2:1,2:))]
+  character(*), parameter :: e(*,*) =  (c(2:1,2:))
+  if (len(b) /= 3 .or. size (b) /= 0) stop 1
+  if (len(y) /= 3 .or. size (y) /= 0) stop 2
+  if (len(d) /= 5 .or. size (d) /= 0) stop 3
+  if (len(e) /= 5 .or. any (shape (e) /= [0,2])) stop 4
+end
+
+! { dg-final { scan-tree-dump-not "_gfortran_stop_numeric" "original" } }
--
2.31.1


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

* Re: [PATCH] PR fortran/103692 - [11/12 Regression] ICE in add_init_expr_to_sym, at fortran/decl.c:2062
  2022-01-17 21:58 [PATCH] PR fortran/103692 - [11/12 Regression] ICE in add_init_expr_to_sym, at fortran/decl.c:2062 Harald Anlauf
@ 2022-01-17 22:24 ` Thomas Koenig
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Koenig @ 2022-01-17 22:24 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches

Hi Harald,

> after lengthy debugging of this PR it became obvious that we killed
> the typespec while trying to expand an empty array constructor.
> 
> Bad idea, but easy to fix.
> 
> Regtested on x86_64-pc-linux-gnu.  OK for mainline and 11-branch?

OK.

Thanks for the patch!

Best regards

	Thomas


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

end of thread, other threads:[~2022-01-17 22:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-17 21:58 [PATCH] PR fortran/103692 - [11/12 Regression] ICE in add_init_expr_to_sym, at fortran/decl.c:2062 Harald Anlauf
2022-01-17 22:24 ` Thomas Koenig

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