re PR fortran/65677 (Incomplete assignment on deferred-length character variable)
authorPaul Thomas <pault@gcc.gnu.org>
Sat, 29 Sep 2018 17:17:09 +0000 (17:17 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Sat, 29 Sep 2018 17:17:09 +0000 (17:17 +0000)
2018-09-29  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-29  Paul Thomas  <pault@gcc.gnu.org>

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

From-SVN: r264715

gcc/fortran/ChangeLog
gcc/fortran/trans-expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/dependency_52.f90 [new file with mode: 0644]

index 86d0a3ee9697a9bc01aff406041dbce053c12375..ffada92df3149171981e93a5d21e660aefe8fc14 100644 (file)
@@ -1,3 +1,9 @@
+2018-09-29  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-25  Martin Liska  <mliska@suse.cz>
 
        PR fortran/87394
index 04210a4b6b137c9b7c9a5a70883afdc24f391718..9824848019d36a2cf4f52b7f43de919c8263b924 100644 (file)
@@ -10207,7 +10207,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;
 
index 2ef07c5202bc306d1ff7f969e1b1ead9175db38b..530e7deba314f161c03e903f1f4516413270778d 100644 (file)
@@ -1,3 +1,8 @@
+2018-09-29  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/65667
+       * gfortran.dg/dependency_52.f90 : New test.
+
 2018-09-29  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/87467
diff --git a/gcc/testsuite/gfortran.dg/dependency_52.f90 b/gcc/testsuite/gfortran.dg/dependency_52.f90
new file mode 100644 (file)
index 0000000..20c97ca
--- /dev/null
@@ -0,0 +1,45 @@
+! { 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