Commit 0ada0dc0 by Paul Thomas

re PR fortran/84931 (Expansion of array constructor with constant implied-do-object goes sideways)

2018-03-30  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/84931
	* simplify.c (gfc_convert_constant): Handle case of array
	constructors within an array that has no iterator and improve
	the conciseness of this section of code.

2018-03-30  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/84931
	* gfortran.dg/array_constructor_53.f90: New test.

From-SVN: r258977
parent 13b5a6bf
2018-03-30 Paul Thomas <pault@gcc.gnu.org>
PR fortran/84931
* simplify.c (gfc_convert_constant): Handle case of array
constructors within an array that has no iterator and improve
the conciseness of this section of code.
2017-03-30 Thomas Koenig <tkoenig@gcc.gnu.org> 2017-03-30 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/85111 PR fortran/85111
......
...@@ -7879,8 +7879,8 @@ gfc_simplify_xor (gfc_expr *x, gfc_expr *y) ...@@ -7879,8 +7879,8 @@ gfc_simplify_xor (gfc_expr *x, gfc_expr *y)
gfc_expr * gfc_expr *
gfc_convert_constant (gfc_expr *e, bt type, int kind) gfc_convert_constant (gfc_expr *e, bt type, int kind)
{ {
gfc_expr *g, *result, *(*f) (gfc_expr *, int); gfc_expr *result, *(*f) (gfc_expr *, int);
gfc_constructor *c; gfc_constructor *c, *t;
switch (e->ts.type) switch (e->ts.type)
{ {
...@@ -8017,31 +8017,24 @@ gfc_convert_constant (gfc_expr *e, bt type, int kind) ...@@ -8017,31 +8017,24 @@ gfc_convert_constant (gfc_expr *e, bt type, int kind)
gfc_expr *tmp; gfc_expr *tmp;
if (c->iterator == NULL) if (c->iterator == NULL)
{ {
if (c->expr->expr_type == EXPR_ARRAY)
tmp = gfc_convert_constant (c->expr, type, kind);
else
tmp = f (c->expr, kind); tmp = f (c->expr, kind);
if (tmp == NULL) }
else
tmp = gfc_convert_constant (c->expr, type, kind);
if (tmp == NULL || tmp == &gfc_bad_expr)
{ {
gfc_free_expr (result); gfc_free_expr (result);
return NULL; return NULL;
} }
gfc_constructor_append_expr (&result->value.constructor, t = gfc_constructor_append_expr (&result->value.constructor,
tmp, &c->where); tmp, &c->where);
} if (c->iterator)
else t->iterator = gfc_copy_iterator (c->iterator);
{
gfc_constructor *n;
g = gfc_convert_constant (c->expr, type, kind);
if (g == NULL || g == &gfc_bad_expr)
{
gfc_free_expr (result);
return g;
}
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);
}
} }
break; break;
......
2018-03-30 Paul Thomas <pault@gcc.gnu.org>
PR fortran/84931
* gfortran.dg/array_constructor_53.f90: New test.
2018-03-30 Thomas Koenig <tkoenig@gcc.gnu.org> 2018-03-30 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/85130 PR fortran/85130
......
! { dg-do run }
! PR 84931 - long array constructors with type conversion were not
! handled correctly. array_constructor_52.f90 tests the original
! problem.
program test
implicit none
integer, parameter :: n = 2**16 + 1
real, dimension(n) :: y
real, dimension(2*n) :: z
integer :: i
y = [33, (1, i=1, n-1) ] ! Check that something more complicated works
if (int(y(3)) /= 1) stop 1
z = [[(1, i=1, n) ],[(2, i=1, n) ]] ! Failed with first version of the fix
if (int(z(2)) /= 1) stop 2
if (int(z(n+1)) /= 2) stop 3
end program test
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment