Fortran] PR 92208 don't use function-result dummy variable as actual argument
authorTobias Burnus <tobias@codesourcery.com>
Wed, 30 Oct 2019 20:01:36 +0000 (20:01 +0000)
committerTobias Burnus <burnus@gcc.gnu.org>
Wed, 30 Oct 2019 20:01:36 +0000 (21:01 +0100)
        PR fortran/92208
        * trans-array.c (gfc_conv_array_parameter): Only copy
        string-length backend_decl if expression is not a function.

        PR fortran/92208
        * gfortran.dg/pr92208.f90: New.

From-SVN: r277639

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

index 0e8de4b2576eab47d7485fffd98bdf9c83bd074e..b86ea10a7e32f455dd42396379d96d5b371afd11 100644 (file)
@@ -1,3 +1,9 @@
+2019-10-30  Tobias Burnus  <tobias@codesourcery.com>
+
+       PR fortran/92208
+       * trans-array.c (gfc_conv_array_parameter): Only copy
+       string-length backend_decl if expression is not a function.
+
 2019-10-30  Mark Eggleston  <mark.eggleston@codethink.com>
 
        * invoke.texi: Add -Wno-overwrite-recursive to list of options. Add
index 437892a6abf21eb6f46146a71b4c34b48a7df352..2d85bf78c42aea6ecc5757c9152019b5d38ff158 100644 (file)
@@ -8049,7 +8049,7 @@ gfc_conv_array_parameter (gfc_se * se, gfc_expr * expr, bool g77,
          /* The components shall be deallocated before their containing entity.  */
          gfc_prepend_expr_to_block (&se->post, tmp);
        }
-      if (expr->ts.type == BT_CHARACTER)
+      if (expr->ts.type == BT_CHARACTER && expr->expr_type != EXPR_FUNCTION)
        se->string_length = expr->ts.u.cl->backend_decl;
       if (size)
        array_parameter_size (se->expr, expr, size);
index ec613497bbce18eeb813b1eb52faffb9e9bd755d..c2d63003f9bf425154a76ac016a9993b0e63c3c3 100644 (file)
@@ -1,3 +1,8 @@
+2019-10-30  Tobias Burnus  <tobias@codesourcery.com>
+
+       PR fortran/92208
+       * gfortran.dg/pr92208.f90: New.
+
 2019-10-30  Marek Polacek  <polacek@redhat.com>
 
        PR c++/92134 - constinit malfunction in static data member.
diff --git a/gcc/testsuite/gfortran.dg/pr92208.f90 b/gcc/testsuite/gfortran.dg/pr92208.f90
new file mode 100644 (file)
index 0000000..9de7f4b
--- /dev/null
@@ -0,0 +1,39 @@
+! { dg-do run }
+!
+! PR fortran/92208
+!
+! Contributed by Nils Reiche
+!
+program stringtest
+  implicit none
+  integer, parameter :: noVars = 2
+
+!  print*, "varNames: ", createVarnames("var",noVars)
+  call function1(noVars,createVarnames("var",noVars),"path")
+
+contains
+
+function createVarnames(string,noVars) result(stringArray)
+  implicit none
+  character(len=*),                        intent(in)  :: string
+  integer,                                 intent(in)  :: noVars
+  character(len=len_trim(string)+6), dimension(noVars) :: stringArray
+  integer :: i
+  do i=1,noVars
+    write(stringArray(i),'(a,i0)') string, i
+  enddo
+end function createVarnames
+
+subroutine function1(noVars,varNames,path)
+  implicit none
+  integer, intent(in)  :: noVars
+  character(len=*), intent(in)  :: path
+  character(len=*), dimension(noVars) :: varNames
+
+  if (path /= 'path') stop 1
+  if (any(varNames /= ['var1', 'var2'])) stop 2
+  !print*, "function1-path    : ", trim(path)
+  !print*, "function1-varNames: ", varNames
+end subroutine function1
+
+end program stringtest