diff options
author | Tobias Burnus <burnus@net-b.de> | 2010-08-04 13:51:32 +0200 |
---|---|---|
committer | Tobias Burnus <burnus@gcc.gnu.org> | 2010-08-04 13:51:32 +0200 |
commit | a48a91732b5252f6be1f0b3d54bfb1da52947caf (patch) | |
tree | 9ee4d951e1aaa29f3f08cdd47228251f110c2d47 /gcc/fortran/resolve.c | |
parent | 48176d810041c2d6a68ddd315044307044d00d07 (diff) | |
download | gcc-a48a91732b5252f6be1f0b3d54bfb1da52947caf.zip gcc-a48a91732b5252f6be1f0b3d54bfb1da52947caf.tar.gz gcc-a48a91732b5252f6be1f0b3d54bfb1da52947caf.tar.bz2 |
re PR fortran/44857 (ICE in output_constructor_regular_field, at varasm.c:4996)
2010-08-04 Tobias Burnus <burnus@net-b.de>
PR fortran/44857
* resolve.c (resolve_structure_cons): Fix handling of
initialization structcture constructors with character
elements of the wrong length.
* array.c (gfc_check_iter_variable): Add NULL check.
(gfc_resolve_character_array_constructor): Also truncate
character length.
2010-08-04 Tobias Burnus <burnus@net-b.de>
PR fortran/44857
* gfortran.dg/derived_constructor_char_1.f90: New.
* gfortran.dg/derived_constructor_char_2.f90: New.
From-SVN: r162863
Diffstat (limited to 'gcc/fortran/resolve.c')
-rw-r--r-- | gcc/fortran/resolve.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 90d193c..620df03 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -901,6 +901,52 @@ resolve_structure_cons (gfc_expr *expr) t = gfc_convert_type (cons->expr, &comp->ts, 1); } + /* For strings, the length of the constructor should be the same as + the one of the structure, ensure this if the lengths are known at + compile time and when we are dealing with PARAMETER or structure + constructors. */ + if (cons->expr->ts.type == BT_CHARACTER && comp->ts.u.cl + && comp->ts.u.cl->length + && comp->ts.u.cl->length->expr_type == EXPR_CONSTANT + && cons->expr->ts.u.cl && cons->expr->ts.u.cl->length + && cons->expr->ts.u.cl->length->expr_type == EXPR_CONSTANT + && mpz_cmp (cons->expr->ts.u.cl->length->value.integer, + comp->ts.u.cl->length->value.integer) != 0) + { + if (cons->expr->expr_type == EXPR_VARIABLE + && cons->expr->symtree->n.sym->attr.flavor == FL_PARAMETER) + { + /* Wrap the parameter in an array constructor (EXPR_ARRAY) + to make use of the gfc_resolve_character_array_constructor + machinery. The expression is later simplified away to + an array of string literals. */ + gfc_expr *para = cons->expr; + cons->expr = gfc_get_expr (); + cons->expr->ts = para->ts; + cons->expr->where = para->where; + cons->expr->expr_type = EXPR_ARRAY; + cons->expr->rank = para->rank; + cons->expr->shape = gfc_copy_shape (para->shape, para->rank); + gfc_constructor_append_expr (&cons->expr->value.constructor, + para, &cons->expr->where); + } + if (cons->expr->expr_type == EXPR_ARRAY) + { + gfc_constructor *p; + p = gfc_constructor_first (cons->expr->value.constructor); + if (cons->expr->ts.u.cl != p->expr->ts.u.cl) + { + gfc_free_expr (cons->expr->ts.u.cl->length); + gfc_free (cons->expr->ts.u.cl); + } + + cons->expr->ts.u.cl = gfc_get_charlen (); + cons->expr->ts.u.cl->length_from_typespec = true; + cons->expr->ts.u.cl->length = gfc_copy_expr (comp->ts.u.cl->length); + gfc_resolve_character_array_constructor (cons->expr); + } + } + if (cons->expr->expr_type == EXPR_NULL && !(comp->attr.pointer || comp->attr.allocatable || comp->attr.proc_pointer |