diff options
author | Jakub Jelinek <jakub@redhat.com> | 2011-06-30 12:25:40 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2011-06-30 12:25:40 +0200 |
commit | 21ea4922aceb3ffa50c3d00b8d26da6b41af92cf (patch) | |
tree | f873fddb9973169bde2c078e90368a59e90983c7 /gcc/fortran/constructor.c | |
parent | f7069d58f6b79b685000544981eb4d05d8261bf9 (diff) |
re PR fortran/49540 (Memory-hog with large DATA stmt)
PR fortran/49540
* gfortran.h (gfc_constructor): Add repeat field.
* trans-array.c (gfc_conv_array_initializer): Handle repeat > 1.
* array.c (current_expand): Add repeat field.
(expand_constructor): Copy repeat.
* constructor.c (node_free, node_copy, gfc_constructor_get,
gfc_constructor_lookup): Handle repeat field.
(gfc_constructor_lookup_next, gfc_constructor_remove): New functions.
* data.h (gfc_assign_data_value): Add mpz_t * argument.
(gfc_assign_data_value_range): Removed.
* constructor.h (gfc_constructor_advance): Removed.
(gfc_constructor_lookup_next, gfc_constructor_remove): New prototypes.
* data.c (gfc_assign_data_value): Add REPEAT argument, handle it and
also handle overwriting a range with a single entry.
(gfc_assign_data_value_range): Removed.
* resolve.c (check_data_variable): Adjust gfc_assign_data_value
call. Use gfc_assign_data_value instead of
gfc_assign_data_value_expr.
* gfortran.dg/pr49540-1.f90: New test.
* gfortran.dg/pr49540-2.f90: New test.
From-SVN: r175693
Diffstat (limited to 'gcc/fortran/constructor.c')
-rw-r--r-- | gcc/fortran/constructor.c | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/gcc/fortran/constructor.c b/gcc/fortran/constructor.c index 97399812d32..600488d640f 100644 --- a/gcc/fortran/constructor.c +++ b/gcc/fortran/constructor.c @@ -1,5 +1,5 @@ /* Array and structure constructors - Copyright (C) 2009, 2010 + Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. This file is part of GCC. @@ -36,6 +36,7 @@ node_free (splay_tree_value value) gfc_free_iterator (c->iterator, 1); mpz_clear (c->offset); + mpz_clear (c->repeat); free (c); } @@ -54,6 +55,7 @@ node_copy (splay_tree_node node, void *base) c->n.component = src->n.component; mpz_init_set (c->offset, src->offset); + mpz_init_set (c->repeat, src->repeat); return c; } @@ -78,6 +80,7 @@ gfc_constructor_get (void) c->iterator = NULL; mpz_init_set_si (c->offset, 0); + mpz_init_set_si (c->repeat, 1); return c; } @@ -169,6 +172,7 @@ gfc_constructor_insert_expr (gfc_constructor_base *base, gfc_constructor * gfc_constructor_lookup (gfc_constructor_base base, int offset) { + gfc_constructor *c; splay_tree_node node; if (!base) @@ -176,9 +180,24 @@ gfc_constructor_lookup (gfc_constructor_base base, int offset) node = splay_tree_lookup (base, (splay_tree_key) offset); if (node) - return (gfc_constructor*) node->value; + return (gfc_constructor *) node->value; - return NULL; + /* Check if the previous node has a repeat count big enough to + cover the offset looked for. */ + node = splay_tree_predecessor (base, (splay_tree_key) offset); + if (!node) + return NULL; + + c = (gfc_constructor *) node->value; + if (mpz_cmp_si (c->repeat, 1) > 0) + { + if (mpz_get_si (c->offset) + mpz_get_si (c->repeat) <= offset) + c = NULL; + } + else + c = NULL; + + return c; } @@ -232,3 +251,27 @@ gfc_constructor_next (gfc_constructor *ctor) else return NULL; } + + +void +gfc_constructor_remove (gfc_constructor *ctor) +{ + if (ctor) + splay_tree_remove (ctor->base, mpz_get_si (ctor->offset)); +} + + +gfc_constructor * +gfc_constructor_lookup_next (gfc_constructor_base base, int offset) +{ + splay_tree_node node; + + if (!base) + return NULL; + + node = splay_tree_successor (base, (splay_tree_key) offset); + if (!node) + return NULL; + + return (gfc_constructor *) node->value; +} |