PR fortran/99206 - [11 Regression] ICE in add_init_expr_to_sym, at fortran/decl.c:1980

Message ID trinity-4b4ac784-5916-408f-b43e-28874dc1c7ac-1614028443304@3c-app-gmx-bs32
State New
Headers show
Series
  • PR fortran/99206 - [11 Regression] ICE in add_init_expr_to_sym, at fortran/decl.c:1980
Related show

Commit Message

Kewen.Lin via Gcc-patches Feb. 22, 2021, 9:14 p.m.
Dear all,

when simplifying the RESHAPE intrinsic we lost the string length when
the resulting array had size zero.  The attached patch sets the resulting
length from the source.

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

Thanks,
Harald


PR fortran/99206 - ICE in add_init_expr_to_sym, at fortran/decl.c:1980

Make sure that the string length is properly set during simplification
even when the resulting array is zero-sized.

gcc/fortran/ChangeLog:

	PR fortran/99206
	* simplify.c (gfc_simplify_reshape): Set string length for
	character arguments.

gcc/testsuite/ChangeLog:

	PR fortran/99206
	* gfortran.dg/reshape_zerosize_4.f90: New test.

Comments

Jerry DeLisle Feb. 23, 2021, 1:24 a.m. | #1
Hi Harald, Looks Good to Me.

OK

Thanks

On 2/22/21 1:14 PM, Harald Anlauf via Fortran wrote:
> Dear all,

>

> when simplifying the RESHAPE intrinsic we lost the string length when

> the resulting array had size zero.  The attached patch sets the resulting

> length from the source.

>

> Regtested on x86_64-pc-linux-gnu.  OK for mainline?

>

> Thanks,

> Harald

>

>

> PR fortran/99206 - ICE in add_init_expr_to_sym, at fortran/decl.c:1980

>

> Make sure that the string length is properly set during simplification

> even when the resulting array is zero-sized.

>

> gcc/fortran/ChangeLog:

>

> 	PR fortran/99206

> 	* simplify.c (gfc_simplify_reshape): Set string length for

> 	character arguments.

>

> gcc/testsuite/ChangeLog:

>

> 	PR fortran/99206

> 	* gfortran.dg/reshape_zerosize_4.f90: New test.

>

Patch

diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 35f267db588..388aca7c38c 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -6887,6 +6887,8 @@  gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp,
 			       &source->where);
   if (source->ts.type == BT_DERIVED)
     result->ts.u.derived = source->ts.u.derived;
+  if (source->ts.type == BT_CHARACTER && result->ts.u.cl == NULL)
+    result->ts = source->ts;
   result->rank = rank;
   result->shape = gfc_get_shape (rank);
   for (i = 0; i < rank; i++)
diff --git a/gcc/testsuite/gfortran.dg/reshape_zerosize_4.f90 b/gcc/testsuite/gfortran.dg/reshape_zerosize_4.f90
new file mode 100644
index 00000000000..d9a0d217271
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/reshape_zerosize_4.f90
@@ -0,0 +1,14 @@ 
+! { dg-do run }
+! PR fortran/99206 - ICE in add_init_expr_to_sym, at fortran/decl.c:1980
+! Check simplifier of RESHAPE for character arrays.
+
+program p
+  character(*),        parameter :: a(0) = reshape([  'ab'], [0])
+  character(*,kind=4), parameter :: c(0) = reshape([4_'cd'], [0])
+  if (len (a)                       /= 2) stop 1
+  if (len (reshape (  ['ab'], [0])) /= 2) stop 2
+  if (kind(reshape (  ['ab'], [0])) /= 1) stop 3
+  if (len (c)                       /= 2) stop 4
+  if (len (reshape ([4_'cd'], [0])) /= 2) stop 5
+  if (kind(reshape ([4_'cd'], [0])) /= 4) stop 6
+end