diff options
author | Paul Thomas <pault@gcc.gnu.org> | 2006-07-04 20:15:52 +0000 |
---|---|---|
committer | Paul Thomas <pault@gcc.gnu.org> | 2006-07-04 20:15:52 +0000 |
commit | 1855915abe6888b17861d36e8174bf954eb8ed86 (patch) | |
tree | 2463384e73151c98e251c62c5a975477a2bbcc92 /gcc/fortran/trans-array.c | |
parent | 6215885d43d8ebe55454794cedfe092604f62718 (diff) | |
download | gcc-1855915abe6888b17861d36e8174bf954eb8ed86.zip gcc-1855915abe6888b17861d36e8174bf954eb8ed86.tar.gz gcc-1855915abe6888b17861d36e8174bf954eb8ed86.tar.bz2 |
re PR fortran/28174 (Corruption of multiple character arrays when passing array sections)
2006-07-04 Paul Thomas <pault@gcc.gnu.org>
PR fortran/28174
* trans-array.c (gfc_conv_expr_descriptor): When building temp,
ensure that the substring reference uses a new charlen.
* trans-expr.c (gfc_conv_aliased_arg): Add the formal intent to
the argument list, lift the treatment of missing string lengths
from the above and implement the use of the intent.
(gfc_conv_function_call): Add the extra argument to the call to
the above.
PR fortran/28167
* trans-array.c (get_array_ctor_var_strlen): Treat a constant
substring reference.
* array.c (gfc_resolve_character_array_constructor): Remove
static attribute and add the gfc_ prefix, make use of element
charlens for the expression and pick up constant string lengths
for expressions that are not themselves constant.
* gfortran.h : resolve_character_array_constructor prototype
added.
* resolve.c (gfc_resolve_expr): Call resolve_character_array_
constructor again after expanding the constructor, to ensure
that the character length is passed to the expression.
2006-07-04 Paul Thomas <pault@gcc.gnu.org>
PR fortran/28174
* gfortran.dg/actual_array_substr_2.f90: New test.
PR fortran/28167
* gfortran.dg/actual_array_constructor_2.f90: New test.
From-SVN: r115182
Diffstat (limited to 'gcc/fortran/trans-array.c')
-rw-r--r-- | gcc/fortran/trans-array.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 6a2c2de..01c78d4 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -1341,6 +1341,7 @@ get_array_ctor_var_strlen (gfc_expr * expr, tree * len) { gfc_ref *ref; gfc_typespec *ts; + mpz_t char_len; /* Don't bother if we already know the length is a constant. */ if (*len && INTEGER_CST_P (*len)) @@ -1360,6 +1361,19 @@ get_array_ctor_var_strlen (gfc_expr * expr, tree * len) ts = &ref->u.c.component->ts; break; + case REF_SUBSTRING: + if (ref->u.ss.start->expr_type != EXPR_CONSTANT + || ref->u.ss.start->expr_type != EXPR_CONSTANT) + break; + mpz_init_set_ui (char_len, 1); + mpz_add (char_len, char_len, ref->u.ss.end->value.integer); + mpz_sub (char_len, char_len, ref->u.ss.start->value.integer); + *len = gfc_conv_mpz_to_tree (char_len, + gfc_default_character_kind); + *len = convert (gfc_charlen_type_node, *len); + mpz_clear (char_len); + return; + default: /* TODO: Substrings are tricky because we can't evaluate the expression more than once. For now we just give up, and hope @@ -4192,7 +4206,10 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss) if (char_ref->type == REF_SUBSTRING) { mpz_t char_len; - expr->ts.cl = char_ref->u.ss.length; + expr->ts.cl = gfc_get_charlen (); + expr->ts.cl->next = char_ref->u.ss.length->next; + char_ref->u.ss.length->next = expr->ts.cl; + mpz_init_set_ui (char_len, 1); mpz_add (char_len, char_len, char_ref->u.ss.end->value.integer); |