diff options
author | Harald Anlauf <anlauf@gmx.de> | 2022-02-06 21:47:20 +0100 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2022-02-09 22:13:53 +0100 |
commit | f3ffea93ef31c03ad8cdcb54e71ec868b57b264f (patch) | |
tree | b54428211044161b14105f4c07a0fba1f472bfc7 /gcc/fortran/arith.cc | |
parent | f6ff6738fa25fb012ed208e01de5a84d8668d538 (diff) | |
download | gcc-f3ffea93ef31c03ad8cdcb54e71ec868b57b264f.zip gcc-f3ffea93ef31c03ad8cdcb54e71ec868b57b264f.tar.gz gcc-f3ffea93ef31c03ad8cdcb54e71ec868b57b264f.tar.bz2 |
Fortran: try simplifications during reductions of array constructors
gcc/fortran/ChangeLog:
PR fortran/66193
* arith.cc (reduce_binary_ac): When reducing binary expressions,
try simplification. Handle case of empty constructor.
(reduce_binary_ca): Likewise.
gcc/testsuite/ChangeLog:
PR fortran/66193
* gfortran.dg/array_constructor_55.f90: New test.
Diffstat (limited to 'gcc/fortran/arith.cc')
-rw-r--r-- | gcc/fortran/arith.cc | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/gcc/fortran/arith.cc b/gcc/fortran/arith.cc index b3323ecf..06e032e 100644 --- a/gcc/fortran/arith.cc +++ b/gcc/fortran/arith.cc @@ -1305,6 +1305,8 @@ reduce_binary_ac (arith (*eval) (gfc_expr *, gfc_expr *, gfc_expr **), head = gfc_constructor_copy (op1->value.constructor); for (c = gfc_constructor_first (head); c; c = gfc_constructor_next (c)) { + gfc_simplify_expr (c->expr, 0); + if (c->expr->expr_type == EXPR_CONSTANT) rc = eval (c->expr, op2, &r); else @@ -1321,9 +1323,19 @@ reduce_binary_ac (arith (*eval) (gfc_expr *, gfc_expr *, gfc_expr **), else { gfc_constructor *c = gfc_constructor_first (head); - r = gfc_get_array_expr (c->expr->ts.type, c->expr->ts.kind, - &op1->where); - r->shape = gfc_copy_shape (op1->shape, op1->rank); + if (c) + { + r = gfc_get_array_expr (c->expr->ts.type, c->expr->ts.kind, + &op1->where); + r->shape = gfc_copy_shape (op1->shape, op1->rank); + } + else + { + gcc_assert (op1->ts.type != BT_UNKNOWN); + r = gfc_get_array_expr (op1->ts.type, op1->ts.kind, + &op1->where); + r->shape = gfc_get_shape (op1->rank); + } r->rank = op1->rank; r->value.constructor = head; *result = r; @@ -1345,6 +1357,8 @@ reduce_binary_ca (arith (*eval) (gfc_expr *, gfc_expr *, gfc_expr **), head = gfc_constructor_copy (op2->value.constructor); for (c = gfc_constructor_first (head); c; c = gfc_constructor_next (c)) { + gfc_simplify_expr (c->expr, 0); + if (c->expr->expr_type == EXPR_CONSTANT) rc = eval (op1, c->expr, &r); else @@ -1361,9 +1375,19 @@ reduce_binary_ca (arith (*eval) (gfc_expr *, gfc_expr *, gfc_expr **), else { gfc_constructor *c = gfc_constructor_first (head); - r = gfc_get_array_expr (c->expr->ts.type, c->expr->ts.kind, - &op2->where); - r->shape = gfc_copy_shape (op2->shape, op2->rank); + if (c) + { + r = gfc_get_array_expr (c->expr->ts.type, c->expr->ts.kind, + &op2->where); + r->shape = gfc_copy_shape (op2->shape, op2->rank); + } + else + { + gcc_assert (op2->ts.type != BT_UNKNOWN); + r = gfc_get_array_expr (op2->ts.type, op2->ts.kind, + &op2->where); + r->shape = gfc_get_shape (op2->rank); + } r->rank = op2->rank; r->value.constructor = head; *result = r; |