* [PATCH] PR fortran/99206 - [11 Regression] ICE in add_init_expr_to_sym, at fortran/decl.c:1980
@ 2021-02-22 21:14 Harald Anlauf
2021-02-23 1:24 ` Jerry DeLisle
0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2021-02-22 21:14 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 658 bytes --]
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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr99206.patch --]
[-- Type: text/x-patch, Size: 1395 bytes --]
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] PR fortran/99206 - [11 Regression] ICE in add_init_expr_to_sym, at fortran/decl.c:1980
2021-02-22 21:14 [PATCH] PR fortran/99206 - [11 Regression] ICE in add_init_expr_to_sym, at fortran/decl.c:1980 Harald Anlauf
@ 2021-02-23 1:24 ` Jerry DeLisle
0 siblings, 0 replies; 2+ messages in thread
From: Jerry DeLisle @ 2021-02-23 1:24 UTC (permalink / raw)
To: Harald Anlauf, fortran, gcc-patches
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.
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-02-23 1:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-22 21:14 [PATCH] PR fortran/99206 - [11 Regression] ICE in add_init_expr_to_sym, at fortran/decl.c:1980 Harald Anlauf
2021-02-23 1:24 ` Jerry DeLisle
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).