From aa53a3f7fba14b04b0ec251a1fa62290d0b4f8ac Mon Sep 17 00:00:00 2001 From: pault Date: Sat, 17 Feb 2018 11:07:32 +0000 Subject: 2018-02-17 Paul Thomas PR fortran/84115 * resolve.c (resolve_assoc_var): If a non-constant target expr. has no string length expression, make the associate variable into a deferred length, allocatable symbol. * trans-decl.c (gfc_is_reallocatable_lhs): Add and use a ptr to the symbol. * trans-stmt.c (trans_associate_var): Null and free scalar associate names that are allocatable. After assignment, remove the allocatable attribute to prevent reallocation. 2018-02-17 Paul Thomas PR fortran/84115 * gfortran.dg/associate_35.f90: Remove error, add stop n's and change to run. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@257781 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/primary.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/fortran/primary.c') diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index 3d076736fdc..9e6a8fe0d80 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -2082,7 +2082,7 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag, { bool permissible; - /* These target expressions can ge resolved at any time. */ + /* These target expressions can be resolved at any time. */ permissible = tgt_expr && tgt_expr->symtree && tgt_expr->symtree->n.sym && (tgt_expr->symtree->n.sym->attr.use_assoc || tgt_expr->symtree->n.sym->attr.host_assoc -- cgit v1.2.1 From 59f3708ec9d9fce5e77f8514fc1f778e2cf52604 Mon Sep 17 00:00:00 2001 From: tkoenig Date: Tue, 20 Feb 2018 18:57:34 +0000 Subject: 2018-02-20 Thomas Koenig PR fortran/48890 PR fortran/83823 * primary.c (gfc_convert_to_structure_constructor): For a constant string constructor, make sure the length is correct. 2018-02-20 Thomas Koenig PR fortran/48890 PR fortran/83823 * gfortran.dg/structure_constructor_14.f90: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@257856 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/primary.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'gcc/fortran/primary.c') diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index 9e6a8fe0d80..d889ed10ac3 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -2879,6 +2879,38 @@ gfc_convert_to_structure_constructor (gfc_expr *e, gfc_symbol *sym, gfc_expr **c if (!this_comp) goto cleanup; + /* For a constant string constructor, make sure the length is + correct; truncate of fill with blanks if needed. */ + if (this_comp->ts.type == BT_CHARACTER && !this_comp->attr.allocatable + && this_comp->ts.u.cl && this_comp->ts.u.cl->length + && this_comp->ts.u.cl->length->expr_type == EXPR_CONSTANT + && actual->expr->expr_type == EXPR_CONSTANT) + { + ptrdiff_t c, e; + c = gfc_mpz_get_hwi (this_comp->ts.u.cl->length->value.integer); + e = actual->expr->value.character.length; + + if (c != e) + { + ptrdiff_t i, to; + gfc_char_t *dest; + dest = gfc_get_wide_string (c + 1); + + to = e < c ? e : c; + for (i = 0; i < to; i++) + dest[i] = actual->expr->value.character.string[i]; + + for (i = e; i < c; i++) + dest[i] = ' '; + + dest[c] = '\0'; + free (actual->expr->value.character.string); + + actual->expr->value.character.length = c; + actual->expr->value.character.string = dest; + } + } + comp_tail->val = actual->expr; if (actual->expr != NULL) comp_tail->where = actual->expr->where; -- cgit v1.2.1