From: Thomas Koenig Date: Fri, 30 Mar 2018 09:56:46 +0000 (+0000) Subject: re PR fortran/85111 (ICE in min_max_choose, at fortran/simplify.c:4884 (and others)) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1832cbf8905a5d24075fc7b2aad495ec0e05cbdf;p=gcc.git re PR fortran/85111 (ICE in min_max_choose, at fortran/simplify.c:4884 (and others)) 2017-03-30 Thomas Koenig PR fortran/85111 * array.c (gfc_resolve_character_array_constructor): Early exit for zero-size arrays. * simplify.c (simplify_transformation_to_array): Exit early if the result size is zero. (simplify_minmaxloc_to_array): Likewise. 2017-03-30 Thomas Koenig PR fortran/85111 * gfortran.dg/zero_sized_10.f90: New test. From-SVN: r258973 --- diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index ee13d92fc92..58d611ba4f5 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -2003,6 +2003,20 @@ gfc_resolve_character_array_constructor (gfc_expr *expr) got_charlen: + /* Early exit for zero size arrays. */ + if (expr->shape) + { + mpz_t size; + HOST_WIDE_INT arraysize; + + gfc_array_size (expr, &size); + arraysize = mpz_get_ui (size); + mpz_clear (size); + + if (arraysize == 0) + return true; + } + found_length = -1; if (expr->ts.u.cl->length == NULL) diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 44290ac2741..18295978e42 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -627,7 +627,7 @@ simplify_transformation_to_array (gfc_expr *result, gfc_expr *array, gfc_expr *d n += 1; } - done = false; + done = resultsize <= 0; base = arrayvec; dest = resultvec; while (!done) @@ -5304,7 +5304,7 @@ simplify_minmaxloc_to_array (gfc_expr *result, gfc_expr *array, n += 1; } - done = false; + done = resultsize <= 0; base = arrayvec; dest = resultvec; while (!done) diff --git a/gcc/testsuite/gfortran.dg/zero_sized_10.f90 b/gcc/testsuite/gfortran.dg/zero_sized_10.f90 new file mode 100644 index 00000000000..f152b3aba63 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/zero_sized_10.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! { PR 85111 - this used to ICE. } +! Original test case by Gernhard Steinmetz. +program p + integer, parameter :: a(2,0) = reshape([1,2,3,4], shape(a)) + character, parameter :: ac(2,0) = reshape(['a','b','c','d'], shape(ac)) + integer, parameter :: b(2) = maxloc(a, dim=1) ! { dg-error "Different shape" } + integer, parameter :: c(2) = minloc(a, dim=1) ! { dg-error "Different shape" } + character, parameter :: d(2) = maxval(ac, dim=1) ! { dg-error "Different shape" } + end program p