From: Thomas Koenig Date: Mon, 19 Mar 2018 07:04:35 +0000 (+0000) Subject: re PR fortran/84931 (Expansion of array constructor with constant implied-do-object... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=949d0060b422c03f809fcd17883470c20a15ff4a;p=gcc.git re PR fortran/84931 (Expansion of array constructor with constant implied-do-object goes sideways) 2018-03-19 Thomas Koenig PR fortran/84931 * simplify.c (gfc_convert_constant): Correctly handle iterators for type conversion. 2018-03-19 Thomas Koenig PR fortran/84931 * gfortran.dg/array_constructor_52.f90: New test. From-SVN: r258641 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 7b550aa75db..8db0754f4af 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2018-03-19 Thomas Koenig + + PR fortran/84931 + * simplify.c (gfc_convert_constant): Correctly handle iterators + for type conversion. + 2018-03-18 Steven G. Kargl PR fortran/77414 diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 680e625c130..44290ac2741 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -8016,26 +8016,32 @@ gfc_convert_constant (gfc_expr *e, bt type, int kind) { gfc_expr *tmp; if (c->iterator == NULL) - tmp = f (c->expr, kind); + { + tmp = f (c->expr, kind); + if (tmp == NULL) + { + gfc_free_expr (result); + return NULL; + } + + gfc_constructor_append_expr (&result->value.constructor, + tmp, &c->where); + } else { + gfc_constructor *n; g = gfc_convert_constant (c->expr, type, kind); - if (g == &gfc_bad_expr) + if (g == NULL || g == &gfc_bad_expr) { gfc_free_expr (result); return g; } - tmp = g; - } - - if (tmp == NULL) - { - gfc_free_expr (result); - return NULL; + n = gfc_constructor_get (); + n->expr = g; + n->iterator = gfc_copy_iterator (c->iterator); + n->where = c->where; + gfc_constructor_append (&result->value.constructor, n); } - - gfc_constructor_append_expr (&result->value.constructor, - tmp, &c->where); } break; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a7b96dda966..cdce63d0063 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-03-19 Thomas Koenig + + PR fortran/84931 + * gfortran.dg/array_constructor_52.f90: New test. + 2018-03-17 Steven G. Kargl PR fortran/77414 diff --git a/gcc/testsuite/gfortran.dg/array_constructor_52.f90 b/gcc/testsuite/gfortran.dg/array_constructor_52.f90 new file mode 100644 index 00000000000..63581acf989 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/array_constructor_52.f90 @@ -0,0 +1,11 @@ +! { dg-do run } +! PR 84931 - long array constructors with type conversion were not +! handled correctly. +program test + implicit none + integer, parameter :: n = 2**16 + real, dimension(n) :: y + integer :: i + y = (/ (1, i=1, n) /) + if (y(2) /= 1) stop 1 +end program test