public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR 83975 Set character length to 0 if unknown
@ 2018-01-23  9:31 Janne Blomqvist
  2018-01-23 16:33 ` Thomas Koenig
  0 siblings, 1 reply; 5+ messages in thread
From: Janne Blomqvist @ 2018-01-23  9:31 UTC (permalink / raw)
  To: fortran, gcc-patches; +Cc: Janne Blomqvist

When associating a variable of type character, if the length of the
target isn't known, set it to zero rather than leaving it unset.  This
is not a complete fix for making associate of characters work
properly, but papers over an ICE in the middle-end. See PR 83344 for
more details.

Regtested on x86_64-pc-linux-gnu, Ok for trunk?

gcc/fortran/ChangeLog:

2018-01-23  Janne Blomqvist  <jb@gcc.gnu.org>

	PR 83975
	PR 83344
	* resolve.c (resolve_assoc_var): Set character length to zero if
	target length unknown.

gcc/testsuite/ChangeLog:

2018-01-23  Janne Blomqvist  <jb@gcc.gnu.org>

	PR 83975
	PR 83344
	* gfortran.dg/associate_31.f90: New test.
---
 gcc/fortran/resolve.c                      | 13 ++++++++-----
 gcc/testsuite/gfortran.dg/associate_31.f90 |  8 ++++++++
 2 files changed, 16 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/associate_31.f90

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index a2b892a..f3fc3ca 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -8634,11 +8634,14 @@ resolve_assoc_var (gfc_symbol* sym, bool resolve_target)
       if (!sym->ts.u.cl)
 	sym->ts.u.cl = target->ts.u.cl;
 
-      if (!sym->ts.u.cl->length && !sym->ts.deferred
-	  && target->expr_type == EXPR_CONSTANT)
-	sym->ts.u.cl->length
-	  = gfc_get_int_expr (gfc_charlen_int_kind,
-			      NULL, target->value.character.length);
+      if (!sym->ts.u.cl->length && !sym->ts.deferred)
+	/* TODO: Setting the length to zero if the expression isn't
+	   constant is probably not correct, but at this point we
+	   don't have any better idea what it should be either.  */
+	sym->ts.u.cl->length =
+	  gfc_get_int_expr (gfc_charlen_int_kind, NULL,
+			    target->expr_type == EXPR_CONSTANT ?
+			    target->value.character.length : 0);
     }
 
   /* If the target is a good class object, so is the associate variable.  */
diff --git a/gcc/testsuite/gfortran.dg/associate_31.f90 b/gcc/testsuite/gfortran.dg/associate_31.f90
new file mode 100644
index 0000000..75774c8
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/associate_31.f90
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR 83975, see also PR 83344
+! Testcase contributed by Gerhard Steinmetz
+subroutine s(x)
+  character(*) :: x
+  associate (y => x)
+  end associate
+end subroutine s
-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-02-01 17:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-23  9:31 [PATCH] PR 83975 Set character length to 0 if unknown Janne Blomqvist
2018-01-23 16:33 ` Thomas Koenig
2018-01-23 19:29   ` Janne Blomqvist
2018-02-01  9:05     ` [PATCH] PR 83975 Associate target with non-constant character length Janne Blomqvist
2018-02-01 17:36       ` Thomas Koenig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).