2020-08-28 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/96624
* simplify.c (gfc_simplify_reshape): Detect zero shape and
clear index if found.
gcc/testsuite/
PR fortran/96624
* gfortran.dg/reshape_8.f90 : New test.
if (gfc_is_not_contiguous (array))
return gfc_get_logical_expr (gfc_default_logical_kind, &array->where, 0);
-
+
return NULL;
}
unsigned long j;
size_t nsource;
gfc_expr *e, *result;
+ bool zerosize = false;
/* Check that argument expression types are OK. */
if (!is_constant_array_expr (source)
result->rank = rank;
result->shape = gfc_get_shape (rank);
for (i = 0; i < rank; i++)
- mpz_init_set_ui (result->shape[i], shape[i]);
+ {
+ mpz_init_set_ui (result->shape[i], shape[i]);
+ if (shape[i] == 0)
+ zerosize = true;
+ }
+
+ if (zerosize)
+ goto sizezero;
while (nsource > 0 || npad > 0)
{
break;
}
+sizezero:
+
mpz_clear (index);
return result;
--- /dev/null
+! { dg-do compile }
+! { dg-options "-fdump-tree-original" }
+!
+! Test the fix for PR96624 in which an attempt was made to assign
+! to the zero length temporary created by reshape, resulting in a segfault.
+!
+! Contributed by Dong Shenpo <shenpo.dong@compiler-dev.com>
+!
+program test
+ integer :: a(2,0)
+ a = reshape([1,2,3,4], [2,0])
+ print *, a
+end
+! { dg-final { scan-tree-dump-times "data" 4 "original" } }