public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran] PR 52022 Fix function passing for funcs returning allocatable
@ 2012-01-27 20:38 Tobias Burnus
  0 siblings, 0 replies; only message in thread
From: Tobias Burnus @ 2012-01-27 20:38 UTC (permalink / raw)
  To: gcc patches, gfortran

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

Dear all,

I have committed the attached patch as obvious (Rev. 183643) after 
building and regtesting. I intent to backport it to 4.5 and 4.6.

Tobias


[-- Attachment #2: dummy-proc.diff --]
[-- Type: text/x-patch, Size: 2575 bytes --]

2012-01-27  Tobias Burnus  <burnus@net-b.de>

	PR fortran/52022
	* trans-expr.c (gfc_conv_procedure_call): Fix passing
	of functions, which return allocatables.

2012-01-27  Tobias Burnus  <burnus@net-b.de>

	PR fortran/52022
	* gfortran.dg/dummy_procedure_7.f90: New.

Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c	(Revision 183640)
+++ gcc/fortran/trans-expr.c	(Arbeitskopie)
@@ -3662,7 +3662,8 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol *
 			  || (fsym->attr.proc_pointer
 			      && e->expr_type == EXPR_VARIABLE
 			      && gfc_is_proc_ptr_comp (e, NULL))
-			  || fsym->attr.allocatable))
+			  || (fsym->attr.allocatable
+			      && fsym->attr.flavor != FL_PROCEDURE)))
 		    {
 		      /* Scalar pointer dummy args require an extra level of
 			 indirection. The null pointer already contains
Index: gcc/testsuite/gfortran.dg/dummy_procedure_7.f90
===================================================================
--- gcc/testsuite/gfortran.dg/dummy_procedure_7.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/dummy_procedure_7.f90	(Arbeitskopie)
@@ -0,0 +1,65 @@
+! { dg-do run }
+!
+! PR fortran/52022
+!
+
+module check
+  integer, save :: icheck = 0
+end module check
+
+module t
+implicit none
+      contains
+subroutine  sol(cost)
+   use check
+   interface 
+        function cost(p) result(y) 
+                double precision,dimension(:) :: p
+                double precision,dimension(:),allocatable :: y
+        end function cost
+   end interface
+
+   if (any (cost([1d0,2d0]) /= [2.d0, 4.d0])) call abort ()
+   icheck = icheck + 1
+end subroutine
+
+end module t
+
+module tt
+   procedure(cost1),pointer :: pcost
+contains
+  subroutine init()
+        pcost=>cost1
+  end subroutine
+
+  function cost1(x) result(y)
+        double precision,dimension(:) :: x
+        double precision,dimension(:),allocatable :: y
+        allocate(y(2))
+        y=2d0*x
+  end function cost1
+
+
+
+  function cost(x) result(y)
+        double precision,dimension(:) :: x
+        double precision,dimension(:),allocatable :: y
+        allocate(y(2))
+        y=pcost(x)
+  end function cost
+end module
+
+program test
+        use tt
+        use t
+        use check
+        implicit none
+
+        call init()
+        if (any (cost([3.d0,7.d0]) /= [6.d0, 14.d0])) call abort ()
+        if (icheck /= 0) call abort ()
+        call sol(cost)
+        if (icheck /= 1) call abort ()
+end program test
+
+! { dg-final { cleanup-modules "t tt check" } }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-01-27 20:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-27 20:38 [Patch, Fortran] PR 52022 Fix function passing for funcs returning allocatable Tobias Burnus

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