Re: [Patch][Fortran] PR 92208 don't use function-result dummy variable as actual argument

2019-11-04 Thread Thomas König
Hi Tobias,

I think this is also OK for gcc 9. Backporting regression fixes should always 
be all right under normal circumstances.

Regards

Thomas

Re: [Patch][Fortran] PR 92208 don't use function-result dummy variable as actual argument

2019-11-04 Thread Tobias Burnus

On 10/30/19 8:06 PM, Thomas Koenig wrote:

OK for the trunk and GCC 9?


As far as I can see, this looks good.

So, OK for trunk. If it later turns out that there are problems
caused by this, I suspect we will hear about them soon enough :-)


What shall we do about GCC 9? https://gcc.gnu.org/PR92208 is marked as 
9/10 Regression.


We can either say in the PR: Won't fix (for GCC 9) – or we can backport 
the fix to GCC 9.


Suggestions?

Tobias

PS: GCC 9 patch attached (= trunk patch, only line number changes which 
patch handled); builds and regtests on the gcc-9-branch with 
x86_64-gnu-linux.


2019-11-04  Tobias Burnus  

	gcc/fortran/
	Backported from mainline
	2019-10-30  Tobias Burnus  

	PR fortran/92208
	* trans-array.c (gfc_conv_array_parameter): Only copy
	string-length backend_decl if expression is not a function.

	gcc/testsuite/
	Backported from mainline
	2019-10-30  Tobias Burnus  

	PR fortran/92208
	* gfortran.dg/pr92208.f90: New.
 
Index: gcc/fortran/trans-array.c
===
--- gcc/fortran/trans-array.c	(revision 277781)
+++ gcc/fortran/trans-array.c	(working copy)
@@ -8027,7 +8027,7 @@
 	  /* The components shall be deallocated before their containing entity.  */
 	  gfc_prepend_expr_to_block (>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: gcc/testsuite/gfortran.dg/pr92208.f90
===
--- gcc/testsuite/gfortran.dg/pr92208.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr92208.f90	(working copy)
@@ -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


Re: [Patch][Fortran] PR 92208 don't use function-result dummy variable as actual argument

2019-10-30 Thread Thomas Koenig

Hi Tobias,


OK for the trunk and GCC 9?


As far as I can see, this looks good.

So, OK for trunk. If it later turns out that there are problems
caused by this, I suspect we will hear about them soon enough :-)

Thanks for taking this on!

Regards

Thomas


[Patch][Fortran] PR 92208 don't use function-result dummy variable as actual argument

2019-10-29 Thread Tobias Burnus

For code like:
   call foo(char_array=bar())
gfortran was using the symbol of the (hidden) result-string-length dummy 
argument of "bar" ("..__result") as (hidden) string-length actual 
argument when calling "foo".


Naturally, the middle end was not amused and gave an ICE (with GCC 9 + 10).

For the attached test case (cf. also PR), the LHS (se->string_length) 
already contained the expected string length (MAX_EXPR 
<(integer(kind=8)) D.4012, 0>). While the RHS 
(expr->ts.u.cl->backend_decl) contained the decl of "..__result".


(I have to admit that I do not fully gasp the code, hence, I do not see 
whether there are other missing cases or whether there are corner cases 
where the patch causes wrong code.)


OK for the trunk and GCC 9?

Tobias

	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.

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 437892a6abf..2d85bf78c42 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -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 (>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);
diff --git a/gcc/testsuite/gfortran.dg/pr92208.f90 b/gcc/testsuite/gfortran.dg/pr92208.f90
new file mode 100644
index 000..9de7f4b24b5
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr92208.f90
@@ -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