Commit e207c522 by Paul Thomas

re PR fortran/55901 ([OOP] type is (character(len=*)) misinterpreted as array)

2015-01-18  Paul Thomas  <pault@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-18  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/55901
	* gfortran.dg/associate_1.f03: Allow test for character with
	automatic length.

From-SVN: r219814
parent d28701a2
2015-01-18 Paul Thomas <pault@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 <pault@gcc.gnu.org> 2015-01-17 Paul Thomas <pault@gcc.gnu.org>
PR fortran/64578 PR fortran/64578
......
...@@ -1857,7 +1857,10 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag, ...@@ -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 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 actually is one for now. The final decision will be made at
resolution time, of course. */ 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; sym->attr.dimension = 1;
if ((equiv_flag && gfc_peek_ascii_char () == '(') if ((equiv_flag && gfc_peek_ascii_char () == '(')
......
...@@ -7935,6 +7935,9 @@ resolve_assoc_var (gfc_symbol* sym, bool resolve_target) ...@@ -7935,6 +7935,9 @@ resolve_assoc_var (gfc_symbol* sym, bool resolve_target)
/* Finally resolve if this is an array or not. */ /* Finally resolve if this is an array or not. */
if (sym->attr.dimension && target->rank == 0) 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 %qs at %L is used as array", gfc_error ("Associate-name %qs at %L is used as array",
sym->name, &sym->declared_at); sym->name, &sym->declared_at);
sym->attr.dimension = 0; sym->attr.dimension = 0;
......
...@@ -1494,9 +1494,18 @@ gfc_get_symbol_decl (gfc_symbol * sym) ...@@ -1494,9 +1494,18 @@ gfc_get_symbol_decl (gfc_symbol * sym)
gfc_internal_error ("intrinsic variable which isn't a procedure"); gfc_internal_error ("intrinsic variable which isn't a procedure");
/* Create string length decl first so that they can be used in the /* 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) 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); length = gfc_create_string_length (sym);
}
/* Create the decl for the variable. */ /* Create the decl for the variable. */
decl = build_decl (sym->declared_at.lb->location, decl = build_decl (sym->declared_at.lb->location,
...@@ -1558,6 +1567,8 @@ gfc_get_symbol_decl (gfc_symbol * sym) ...@@ -1558,6 +1567,8 @@ gfc_get_symbol_decl (gfc_symbol * sym)
/* Character variables need special handling. */ /* Character variables need special handling. */
gfc_allocate_lang_decl (decl); gfc_allocate_lang_decl (decl);
/* Associate names can use the hidden string length variable
of their associated target. */
if (TREE_CODE (length) != INTEGER_CST) if (TREE_CODE (length) != INTEGER_CST)
{ {
gfc_finish_var_decl (length, sym); gfc_finish_var_decl (length, sym);
......
2015-01-18 Paul Thomas <pault@gcc.gnu.org>
PR fortran/55901
* gfortran.dg/associate_1.f03: Allow test for character with
automatic length.
2015-01-17 Segher Boessenkool <segher@kernel.crashing.org> 2015-01-17 Segher Boessenkool <segher@kernel.crashing.org>
* gcc.target/powerpc/ppc-fpconv-4.c: Skip for -mpowerpc64. * gcc.target/powerpc/ppc-fpconv-4.c: Skip for -mpowerpc64.
......
...@@ -84,8 +84,7 @@ PROGRAM main ...@@ -84,8 +84,7 @@ PROGRAM main
IF (tp%comp /= 5) CALL abort () IF (tp%comp /= 5) CALL abort ()
! Association to character variables. ! Association to character variables.
! FIXME: Enable character test, once this works. CALL test_char (5)
!CALL test_char (5)
CONTAINS CONTAINS
...@@ -94,7 +93,6 @@ CONTAINS ...@@ -94,7 +93,6 @@ CONTAINS
func = (/ 1, 3, 5 /) func = (/ 1, 3, 5 /)
END FUNCTION func END FUNCTION func
#if 0
! Test association to character variable with automatic length. ! Test association to character variable with automatic length.
SUBROUTINE test_char (n) SUBROUTINE test_char (n)
INTEGER, INTENT(IN) :: n INTEGER, INTENT(IN) :: n
...@@ -109,6 +107,5 @@ CONTAINS ...@@ -109,6 +107,5 @@ CONTAINS
END ASSOCIATE END ASSOCIATE
IF (str /= "abcde") CALL abort () IF (str /= "abcde") CALL abort ()
END SUBROUTINE test_char END SUBROUTINE test_char
#endif
END PROGRAM main END PROGRAM main
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment