public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Paul Richard Thomas <paul.richard.thomas@gmail.com>
To: "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [Patch, fortran] PR65677 - Incomplete assignment on deferred-length character variable
Date: Sun, 23 Sep 2018 12:27:00 -0000	[thread overview]
Message-ID: <CAGkQGiKj1XB7=iy0MuTgNKOgKjfmbd2usWGQTd5UqVVJsjO65g@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 578 bytes --]

This is yet another deferred character length problem that this time
is caused by a dependency in assignment between lhs and rhs
string_lengths. The comment in the testcase explains all.

Bootstraps and regtests on FC21/x86_64 - OK for trunk and 8-branch?

I cannot commit until next week.

Paul

2018-09-23  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/65667
    * trans-expr.c (gfc_trans_assignment_1): If there is dependency
    fix the rse stringlength.

2018-09-23  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/65667
    * gfortran.dg/dependency_52.f90 : New test.

[-- Attachment #2: submit.diff --]
[-- Type: text/x-patch, Size: 712 bytes --]

diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 1453828..6a05412 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -10187,7 +10187,11 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag,
 	   || TREE_CODE (rse.string_length) == INDIRECT_REF))
     string_length = gfc_evaluate_now (rse.string_length, &rse.pre);
   else if (expr2->ts.type == BT_CHARACTER)
-    string_length = rse.string_length;
+    {
+      if (expr1->ts.deferred && gfc_check_dependency (expr1, expr2, false))
+	rse.string_length = gfc_evaluate_now (rse.string_length, &rse.pre);
+      string_length = rse.string_length;
+    }
   else
     string_length = NULL_TREE;
 

[-- Attachment #3: dependency_52.f90 --]
[-- Type: text/x-fortran, Size: 1188 bytes --]

! { dg-do run }
!
! Test the fix for PR65667, in which the dependency was missed and
! the string length of 'text' was decremented twice. The rhs string
! length is now fixed after the function call so that the dependency
! on the length of 'text' is removed for later evaluations.
!
!Contributed by John  <jwmwalrus@gmail.com>
!
module mod1
    implicit none
contains
    subroutine getKeyword(string, keyword, rest)
        character(:), allocatable, intent(IN) :: string
        character(:), allocatable, intent(OUT) :: keyword, rest
        integer :: idx
        character(:), allocatable :: text

        keyword = ''
        rest = ''
        text = string
        text = ADJUSTL(text(2:))    ! Note dependency.
        idx = INDEX(text, ' ')

        if (idx == 0) then
            keyword = TRIM(text)
        else
            keyword = text(:idx-1)
            rest = TRIM(ADJUSTL(text(idx+1:)))
        endif
    end subroutine
end module mod1

    use mod1
    implicit none

    character(:), allocatable :: line, keyword, rest

    line = '@HERE    IT IS'

    call getKeyword(line, keyword, rest)

    if (keyword .ne. 'HERE') stop 1
    if (rest .ne. 'IT IS') stop 2
end

             reply	other threads:[~2018-09-23 11:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-23 12:27 Paul Richard Thomas [this message]
2018-09-23 16:47 ` Janne Blomqvist
2018-09-30 18:11 Dominique d'Humières

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGkQGiKj1XB7=iy0MuTgNKOgKjfmbd2usWGQTd5UqVVJsjO65g@mail.gmail.com' \
    --to=paul.richard.thomas@gmail.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).