diff options
author | Paul Thomas <pault@gcc.gnu.org> | 2021-01-08 10:11:00 +0000 |
---|---|---|
committer | Paul Thomas <pault@gcc.gnu.org> | 2021-01-08 10:11:00 +0000 |
commit | c231fca5de8e455b263495b20a416a5e47d1029a (patch) | |
tree | 4b588ebaee3de6b4c9bd2a5b7f051c60e5f97c0a /gcc | |
parent | 01d92cfd79872e4cffc78bf233bb9b767336beb8 (diff) | |
download | gcc-c231fca5de8e455b263495b20a416a5e47d1029a.zip gcc-c231fca5de8e455b263495b20a416a5e47d1029a.tar.gz gcc-c231fca5de8e455b263495b20a416a5e47d1029a.tar.bz2 |
Fortran:Fix simplification of constructors with implied-do [PR98458]
2021-01-08 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/98458
* simplify.c (is_constant_array_expr): If an array constructor
expression has elements other than constants or structures, try
fixing the expression with gfc_reduce_init_expr. Also, if shape
is NULL, obtain the array size and set it.
gcc/testsuite/
PR fortran/98458
* gfortran.dg/implied_do_3.f90 : New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/fortran/simplify.c | 34 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/implied_do_3.f90 | 14 |
2 files changed, 47 insertions, 1 deletions
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index dac48a8..23317a2 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -220,6 +220,8 @@ static bool is_constant_array_expr (gfc_expr *e) { gfc_constructor *c; + bool array_OK = true; + mpz_t size; if (e == NULL) return true; @@ -235,9 +237,39 @@ is_constant_array_expr (gfc_expr *e) c; c = gfc_constructor_next (c)) if (c->expr->expr_type != EXPR_CONSTANT && c->expr->expr_type != EXPR_STRUCTURE) + { + array_OK = false; + break; + } + + /* Check and expand the constructor. */ + if (!array_OK && gfc_init_expr_flag && e->rank == 1) + { + array_OK = gfc_reduce_init_expr (e); + /* gfc_reduce_init_expr resets the flag. */ + gfc_init_expr_flag = true; + } + else + return array_OK; + + /* Recheck to make sure that any EXPR_ARRAYs have gone. */ + for (c = gfc_constructor_first (e->value.constructor); + c; c = gfc_constructor_next (c)) + if (c->expr->expr_type != EXPR_CONSTANT + && c->expr->expr_type != EXPR_STRUCTURE) return false; - return true; + /* Make sure that the array has a valid shape. */ + if (e->shape == NULL && e->rank == 1) + { + if (!gfc_array_size(e, &size)) + return false; + e->shape = gfc_get_shape (1); + mpz_init_set (e->shape[0], size); + mpz_clear (size); + } + + return array_OK; } /* Test for a size zero array. */ diff --git a/gcc/testsuite/gfortran.dg/implied_do_3.f90 b/gcc/testsuite/gfortran.dg/implied_do_3.f90 new file mode 100644 index 0000000..8206332 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/implied_do_3.f90 @@ -0,0 +1,14 @@ +! { dg-do compile } +! +! Test the fix for PR98458 in which array expressions within the implied-do +! array constructor caused an ICE in trans-array.c(gfc_conv_array_initializer). +! +! Contributed by Xiao Liu <xiao.liu@compiler-dev.com> +! +program test + implicit none + integer :: i + integer, parameter :: t(6) = [1,2,3,4,5,6] + integer, parameter :: tmp(3,2) = reshape([(t(i:i+1),i=1,3)],[3,2]) + print *, tmp ! Used to ICE +end |