diff options
author | Paul Thomas <pault@gcc.gnu.org> | 2007-05-08 11:58:25 +0000 |
---|---|---|
committer | Paul Thomas <pault@gcc.gnu.org> | 2007-05-08 11:58:25 +0000 |
commit | a9b43781dbc0c38ea33062cd96825defbcb1ca2d (patch) | |
tree | 51128533ef6fb2920b355241338a655d8bf897aa /gcc/fortran/decl.c | |
parent | a6d99bb44a3fd7c3bcfb402dc89ae7b3979073c0 (diff) | |
download | gcc-a9b43781dbc0c38ea33062cd96825defbcb1ca2d.zip gcc-a9b43781dbc0c38ea33062cd96825defbcb1ca2d.tar.gz gcc-a9b43781dbc0c38ea33062cd96825defbcb1ca2d.tar.bz2 |
re PR fortran/29397 (Constant logical expression with parameter array)
2007-05-08 Paul Thomas <pault@gcc.gnu.org>
PR fortran/29397
PR fortran/29400
* decl.c (add_init_expr_to_sym): Expand a scalar initializer
for a parameter array into an array expression with the right
shape.
* array.c (spec_dimen_size): Remove static attribute.
* gfortran.h : Prototype for spec_dimen_size.
2007-05-08 Paul Thomas <pault@gcc.gnu.org>
PR fortran/29397
* gfortran.dg/parameter_array_init_1.f90: New test.
PR fortran/29400
* gfortran.dg/parameter_array_init_2.f90: New test.
From-SVN: r124541
Diffstat (limited to 'gcc/fortran/decl.c')
-rw-r--r-- | gcc/fortran/decl.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 1dcc53d..0071f90 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -974,7 +974,44 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, /* Add initializer. Make sure we keep the ranks sane. */ if (sym->attr.dimension && init->rank == 0) - init->rank = sym->as->rank; + { + mpz_t size; + gfc_expr *array; + gfc_constructor *c; + int n; + if (sym->attr.flavor == FL_PARAMETER + && init->expr_type == EXPR_CONSTANT + && spec_size (sym->as, &size) == SUCCESS + && mpz_cmp_si (size, 0) > 0) + { + array = gfc_start_constructor (init->ts.type, init->ts.kind, + &init->where); + + array->value.constructor = c = NULL; + for (n = 0; n < (int)mpz_get_si (size); n++) + { + if (array->value.constructor == NULL) + { + array->value.constructor = c = gfc_get_constructor (); + c->expr = init; + } + else + { + c->next = gfc_get_constructor (); + c = c->next; + c->expr = gfc_copy_expr (init); + } + } + + array->shape = gfc_get_shape (sym->as->rank); + for (n = 0; n < sym->as->rank; n++) + spec_dimen_size (sym->as, n, &array->shape[n]); + + init = array; + mpz_clear (size); + } + init->rank = sym->as->rank; + } sym->value = init; *initp = NULL; |