+2007-09-20 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
+
+ PR fortran/33288
+ * arith.c (reduce_unary, reduce_binary_ac, reduce_binary_ca,
+ reduce_binary_aa): Call ourselves recursively if an element of
+ the constructor is itself a constant array.
+
2007-09-20 Tobias Schlüter <tobi@gcc.gnu.org>
* io.c (resolve_tag_format): New function using code split out
for (c = head; c; c = c->next)
{
- rc = eval (c->expr, &r);
+ rc = reduce_unary (eval, c->expr, &r);
+
if (rc != ARITH_OK)
break;
for (c = head; c; c = c->next)
{
- rc = eval (c->expr, op2, &r);
+ if (c->expr->expr_type == EXPR_CONSTANT)
+ rc = eval (c->expr, op2, &r);
+ else
+ rc = reduce_binary_ac (eval, c->expr, op2, &r);
+
if (rc != ARITH_OK)
break;
for (c = head; c; c = c->next)
{
- rc = eval (op1, c->expr, &r);
+ if (c->expr->expr_type == EXPR_CONSTANT)
+ rc = eval (op1, c->expr, &r);
+ else
+ rc = reduce_binary_ca (eval, op1, c->expr, &r);
+
if (rc != ARITH_OK)
break;
}
+/* We need a forward declaration of reduce_binary. */
+static arith reduce_binary (arith (*eval) (gfc_expr *, gfc_expr *, gfc_expr **),
+ gfc_expr *op1, gfc_expr *op2, gfc_expr **result);
+
+
static arith
reduce_binary_aa (arith (*eval) (gfc_expr *, gfc_expr *, gfc_expr **),
gfc_expr *op1, gfc_expr *op2, gfc_expr **result)
break;
}
- rc = eval (c->expr, d->expr, &r);
+ rc = reduce_binary (eval, c->expr, d->expr, &r);
if (rc != ARITH_OK)
break;
--- /dev/null
+! Simplification of unary and binary expressions containing
+! array constructors.
+!
+! See PR33288
+!
+! { dg-do run }
+ real, parameter :: x(1) = 42
+ real, parameter :: x1(1) = (/ x /) + 1
+ real, parameter :: x2(1) = 1 + (/ x /)
+ real, parameter :: x3(1) = -(/ x /)
+ real, parameter :: x4(2) = (/ x, 1. /) + (/ 2, (/3/) /)
+
+ if (any (x1 /= (/43./))) call abort
+ if (any (x2 /= (/43./))) call abort
+ if (any (x3 /= (/-42./))) call abort
+ if (any (x4 /= (/44., 4./))) call abort
+end