aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2021-02-23 19:09:14 +0100
committerHarald Anlauf <anlauf@gmx.de>2021-02-23 19:09:14 +0100
commita6c7e0fcffc857e67dffdd7609be663cc3aac7d2 (patch)
tree3f7b4f10ac452623e400273b8099feece02d5e6f
parent47145e6916f58e1cd4f562c06fa7289da49f690c (diff)
downloadgcc-a6c7e0fcffc857e67dffdd7609be663cc3aac7d2.zip
gcc-a6c7e0fcffc857e67dffdd7609be663cc3aac7d2.tar.gz
gcc-a6c7e0fcffc857e67dffdd7609be663cc3aac7d2.tar.bz2
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.
-rw-r--r--gcc/fortran/simplify.c2
-rw-r--r--gcc/testsuite/gfortran.dg/reshape_zerosize_4.f9014
2 files changed, 16 insertions, 0 deletions
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 35f267d..388aca7 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 0000000..d9a0d21
--- /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