Dear All, Steve Kargl has pointed out to me that the attachment was a null attachment. As is well known, these are the Swiss Army knife of patches and will fix anything. In fact, this patch was already posted long while since with the PR. However, since I am now in a slightly more pedestrian mood, I have attached it to this message too :-)
Cheers Paul On 17 January 2015 at 11:55, Paul Richard Thomas <paul.richard.tho...@gmail.com> wrote: > Dear All, > > The attached patch fixes the confusion between substrings of character > associate-names and scalars being misused as arrays. > > It is sufficiently obvious and has been tested by Dominique that I > will commit it later today if there are no opinions to the contrary. > > I will now turn my attention to Andre's patches for PR60357 and PR61275. > > Afterwards, I will fix the rest of the fix for this PR, via Andre's > patch for PR60255 and the query in the final message in the thread. > > Bootstrapped and regtested on x86_64/FC21 - OK for trunk? > > Cheers > > Paul > > 2015-01-17 Paul Thomas <pa...@gcc.gnu.org> > > PR fortran/55901 > * primary.c (gfc_match_varspec): Exclude dangling associate- > names with dimension 0 from being counted as arrays. > * resolve.c (resolve_assoc_var): Sub-strings are permissible > for associate-names, so exclude characters from the test for > misuse as arrays. > * trans-decl.c (gfc_get_symbol_decl): Associate-names can use > the hidden string length variable of their associated target. > Signal this by setting 'length' to a constant, if the decl for > the string length is a variable. > > > 2015-01-17 Paul Thomas <pa...@gcc.gnu.org> > > PR fortran/55901 > * gfortran.dg/associate_1.f03: Allow test for character with > automatic length. > > > -- > Outside of a dog, a book is a man's best friend. Inside of a dog it's > too dark to read. > > Groucho Marx -- Outside of a dog, a book is a man's best friend. Inside of a dog it's too dark to read. Groucho Marx
Index: gcc/fortran/primary.c =================================================================== *** gcc/fortran/primary.c (revision 216426) --- gcc/fortran/primary.c (working copy) *************** gfc_match_varspec (gfc_expr *primary, in *** 1855,1861 **** Thus if we have one and parentheses follow, we have to assume that it actually is one for now. The final decision will be made at resolution time, of course. */ ! if (sym->assoc && gfc_peek_ascii_char () == '(') sym->attr.dimension = 1; if ((equiv_flag && gfc_peek_ascii_char () == '(') --- 1855,1864 ---- Thus if we have one and parentheses follow, we have to assume that it actually is one for now. The final decision will be made at resolution time, of course. */ ! if (sym->assoc && gfc_peek_ascii_char () == '(' ! && !(sym->assoc->dangling && sym->assoc->st ! && sym->assoc->st->n.sym ! && sym->assoc->st->n.sym->attr.dimension == 0)) sym->attr.dimension = 1; if ((equiv_flag && gfc_peek_ascii_char () == '(') Index: gcc/fortran/resolve.c =================================================================== *** gcc/fortran/resolve.c (revision 216427) --- gcc/fortran/resolve.c (working copy) *************** resolve_assoc_var (gfc_symbol* sym, bool *** 7882,7887 **** --- 7882,7890 ---- /* Finally resolve if this is an array or not. */ if (sym->attr.dimension && target->rank == 0) { + /* primary.c makes the assumption that a reference to an associate + name followed by a left parenthesis is an array reference. */ + if (sym->ts.type != BT_CHARACTER) gfc_error ("Associate-name '%s' at %L is used as array", sym->name, &sym->declared_at); sym->attr.dimension = 0; Index: gcc/fortran/trans-decl.c =================================================================== *** gcc/fortran/trans-decl.c (revision 216426) --- gcc/fortran/trans-decl.c (working copy) *************** gfc_get_symbol_decl (gfc_symbol * sym) *** 1435,1441 **** --- 1435,1448 ---- /* Create string length decl first so that they can be used in the type declaration. */ if (sym->ts.type == BT_CHARACTER) + { + if (sym->attr.associate_var + && sym->ts.u.cl->backend_decl + && TREE_CODE (sym->ts.u.cl->backend_decl) == VAR_DECL) + length = gfc_index_zero_node; + else length = gfc_create_string_length (sym); + } /* Create the decl for the variable. */ decl = build_decl (sym->declared_at.lb->location, *************** gfc_get_symbol_decl (gfc_symbol * sym) *** 1497,1502 **** --- 1504,1511 ---- /* Character variables need special handling. */ gfc_allocate_lang_decl (decl); + /* Associate names can use the hidden string length variable + of their associated target. */ if (TREE_CODE (length) != INTEGER_CST) { gfc_finish_var_decl (length, sym); Index: gcc/testsuite/gfortran.dg/associate_1.f03 =================================================================== *** gcc/testsuite/gfortran.dg/associate_1.f03 (revision 216426) --- gcc/testsuite/gfortran.dg/associate_1.f03 (working copy) *************** PROGRAM main *** 84,91 **** IF (tp%comp /= 5) CALL abort () ! Association to character variables. ! ! FIXME: Enable character test, once this works. ! !CALL test_char (5) CONTAINS --- 84,90 ---- IF (tp%comp /= 5) CALL abort () ! Association to character variables. ! CALL test_char (5) CONTAINS *************** CONTAINS *** 94,100 **** func = (/ 1, 3, 5 /) END FUNCTION func - #if 0 ! Test association to character variable with automatic length. SUBROUTINE test_char (n) INTEGER, INTENT(IN) :: n --- 93,98 ---- *************** CONTAINS *** 109,114 **** END ASSOCIATE IF (str /= "abcde") CALL abort () END SUBROUTINE test_char - #endif END PROGRAM main --- 107,111 ----