public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/83344 Don't set bogus constant value
@ 2017-12-28 17:37 Janne Blomqvist
  2017-12-28 18:07 ` Steve Kargl
  0 siblings, 1 reply; 2+ messages in thread
From: Janne Blomqvist @ 2017-12-28 17:37 UTC (permalink / raw)
  To: fortran, gcc-patches; +Cc: Janne Blomqvist

This patch does not fix PR 83344, but merely fixes an error where we
used to set a constant character length value from a non-constant
expression, and thus set it to some bogus value.

As a result of this, I have commented out part of the associate_22.f90
test which otherwise generates a warning message.

Regtested on x86_64-pc-linux-gnu, unless there are objections I'll
commit this to trunk in a few days?

gcc/fortran/ChangeLog:

2017-12-28  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/83344
	* resolve.c (resolve_assoc_var): Don't set the constant value
	unless the target is a constant expression.

gcc/testsuite/ChangeLog:

2017-12-28  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/83344
	* gfortran.dg/associate_22.f90: Comment out part of test.
---
 gcc/fortran/resolve.c                      | 3 ++-
 gcc/testsuite/gfortran.dg/associate_22.f90 | 9 +++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index f819b71..cf75a78 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -8627,7 +8627,8 @@ 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)
+      if (!sym->ts.u.cl->length && !sym->ts.deferred
+	  && target->expr_type == EXPR_CONSTANT)
 	sym->ts.u.cl->length
 	  = gfc_get_int_expr (gfc_default_integer_kind,
 			      NULL, target->value.character.length);
diff --git a/gcc/testsuite/gfortran.dg/associate_22.f90 b/gcc/testsuite/gfortran.dg/associate_22.f90
index 1558992..edf5932 100644
--- a/gcc/testsuite/gfortran.dg/associate_22.f90
+++ b/gcc/testsuite/gfortran.dg/associate_22.f90
@@ -24,10 +24,11 @@ program foo
    end associate
 
    ! This failed.
-   a = trim(s) // 'abc'
-   associate(w => trim(s) // 'abc')
-      if (trim(w) /= trim(a)) call abort
-   end associate
+   ! This still doesn't work correctly, see PR 83344
+!   a = trim(s) // 'abc'
+!   associate(w => trim(s) // 'abc')
+!      if (trim(w) /= trim(a)) call abort
+!   end associate
 
    ! This failed.
    associate(x => trim('abc'))
-- 
2.7.4

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

* Re: [PATCH] PR fortran/83344 Don't set bogus constant value
  2017-12-28 17:37 [PATCH] PR fortran/83344 Don't set bogus constant value Janne Blomqvist
@ 2017-12-28 18:07 ` Steve Kargl
  0 siblings, 0 replies; 2+ messages in thread
From: Steve Kargl @ 2017-12-28 18:07 UTC (permalink / raw)
  To: Janne Blomqvist; +Cc: fortran, gcc-patches

On Thu, Dec 28, 2017 at 07:37:44PM +0200, Janne Blomqvist wrote:
> This patch does not fix PR 83344, but merely fixes an error where we
> used to set a constant character length value from a non-constant
> expression, and thus set it to some bogus value.
> 
> As a result of this, I have commented out part of the associate_22.f90
> test which otherwise generates a warning message.
> 
> Regtested on x86_64-pc-linux-gnu, unless there are objections I'll
> commit this to trunk in a few days?
> 

This looks ok to me.

-- 
Steve

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

end of thread, other threads:[~2017-12-28 18:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-28 17:37 [PATCH] PR fortran/83344 Don't set bogus constant value Janne Blomqvist
2017-12-28 18:07 ` Steve Kargl

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).