From: Paul Thomas Date: Sun, 18 Jan 2015 12:21:38 +0000 (+0000) Subject: re PR fortran/55901 ([OOP] type is (character(len=*)) misinterpreted as array) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e207c522623c3d3620416b5332b8a6d8644a1f06;p=gcc.git re PR fortran/55901 ([OOP] type is (character(len=*)) misinterpreted as array) 2015-01-18 Paul Thomas 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-18 Paul Thomas PR fortran/55901 * gfortran.dg/associate_1.f03: Allow test for character with automatic length. From-SVN: r219814 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index d9e0fea8a1a..e91159a8d01 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,16 @@ +2015-01-18 Paul Thomas + + 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 PR fortran/64578 diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index cbe7aa60e7b..141f8cc1ed6 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -1857,7 +1857,10 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag, 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 () == '(') + 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 () == '(') diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 7a16add06b8..a9645a0a214 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -7935,8 +7935,11 @@ resolve_assoc_var (gfc_symbol* sym, bool resolve_target) /* Finally resolve if this is an array or not. */ if (sym->attr.dimension && target->rank == 0) { - gfc_error ("Associate-name %qs at %L is used as array", - sym->name, &sym->declared_at); + /* 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 %qs at %L is used as array", + sym->name, &sym->declared_at); sym->attr.dimension = 0; return; } diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index a73620fe1bb..5beb6f73fb1 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -1494,9 +1494,18 @@ gfc_get_symbol_decl (gfc_symbol * sym) gfc_internal_error ("intrinsic variable which isn't a procedure"); /* Create string length decl first so that they can be used in the - type declaration. */ + type declaration. For associate names, the target character + length is used. Set 'length' to a constant so that if the + string lenght is a variable, it is not finished a second time. */ if (sym->ts.type == BT_CHARACTER) - length = gfc_create_string_length (sym); + { + 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, @@ -1558,6 +1567,8 @@ gfc_get_symbol_decl (gfc_symbol * sym) /* 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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9223d646a43..34e40ff8d42 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2015-01-18 Paul Thomas + + PR fortran/55901 + * gfortran.dg/associate_1.f03: Allow test for character with + automatic length. + 2015-01-17 Segher Boessenkool * gcc.target/powerpc/ppc-fpconv-4.c: Skip for -mpowerpc64. diff --git a/gcc/testsuite/gfortran.dg/associate_1.f03 b/gcc/testsuite/gfortran.dg/associate_1.f03 index d7b14aebeb5..61fa1ac7831 100644 --- a/gcc/testsuite/gfortran.dg/associate_1.f03 +++ b/gcc/testsuite/gfortran.dg/associate_1.f03 @@ -84,8 +84,7 @@ PROGRAM main IF (tp%comp /= 5) CALL abort () ! Association to character variables. - ! FIXME: Enable character test, once this works. - !CALL test_char (5) + CALL test_char (5) CONTAINS @@ -94,7 +93,6 @@ CONTAINS 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 @@ -109,6 +107,5 @@ CONTAINS END ASSOCIATE IF (str /= "abcde") CALL abort () END SUBROUTINE test_char -#endif END PROGRAM main