summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/cray_pointers_9.f90
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gfortran.dg/cray_pointers_9.f90
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gfortran.dg/cray_pointers_9.f90')
-rw-r--r--gcc/testsuite/gfortran.dg/cray_pointers_9.f90104
1 files changed, 104 insertions, 0 deletions
diff --git a/gcc/testsuite/gfortran.dg/cray_pointers_9.f90 b/gcc/testsuite/gfortran.dg/cray_pointers_9.f90
new file mode 100644
index 000000000..81bcb199a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/cray_pointers_9.f90
@@ -0,0 +1,104 @@
+! { dg-do compile }
+! { dg-options "-fcray-pointer" }
+!
+! Test the fix for PR36703 in which the Cray pointer was not passed
+! correctly so that the call to 'fun' at line 102 caused an ICE.
+!
+! Contributed by James van Buskirk on com.lang.fortran
+! http://groups.google.com/group/comp.lang.fortran/msg/b600c081a3654936
+! Reported by Tobias Burnus <burnus@gcc.gnu.org>
+!
+module funcs
+ use ISO_C_BINDING ! Added this USE statement
+ implicit none
+! Interface block for function program fptr will invoke
+! to get the C_FUNPTR
+ interface
+ function get_proc(mess) bind(C,name='BlAh')
+ use ISO_C_BINDING
+ implicit none
+ character(kind=C_CHAR) mess(*)
+ type(C_FUNPTR) get_proc
+ end function get_proc
+ end interface
+end module funcs
+
+module other_fun
+ use ISO_C_BINDING
+ implicit none
+ private
+! Message to be returned by procedure pointed to
+! by the C_FUNPTR
+ character, allocatable, save :: my_message(:)
+! Interface block for the procedure pointed to
+! by the C_FUNPTR
+ public abstract_fun
+ abstract interface
+ function abstract_fun(x)
+ use ISO_C_BINDING
+ import my_message
+ implicit none
+ integer(C_INT) x(:)
+ character(size(my_message),C_CHAR) abstract_fun(size(x))
+ end function abstract_fun
+ end interface
+ contains
+! Procedure to store the message and get the C_FUNPTR
+ function gp(message) bind(C,name='BlAh')
+ character(kind=C_CHAR) message(*)
+ type(C_FUNPTR) gp
+ integer(C_INT64_T) i
+
+ i = 1
+ do while(message(i) /= C_NULL_CHAR)
+ i = i+1
+ end do
+ allocate (my_message(i+1)) ! Added this allocation
+ my_message = message(int(1,kind(i)):i-1)
+ gp = get_funloc(make_mess,aux)
+ end function gp
+
+! Intermediate procedure to pass the function and get
+! back the C_FUNPTR
+ function get_funloc(x,y)
+ procedure(abstract_fun) x
+ type(C_FUNPTR) y
+ external y
+ type(C_FUNPTR) get_funloc
+
+ get_funloc = y(x)
+ end function get_funloc
+
+! Procedure to convert the function to C_FUNPTR
+ function aux(x)
+ interface
+ subroutine x() bind(C)
+ end subroutine x
+ end interface
+ type(C_FUNPTR) aux
+
+ aux = C_FUNLOC(x)
+ end function aux
+
+! Procedure pointed to by the C_FUNPTR
+ function make_mess(x)
+ integer(C_INT) x(:)
+ character(size(my_message),C_CHAR) make_mess(size(x))
+
+ make_mess = transfer(my_message,make_mess(1))
+ end function make_mess
+end module other_fun
+
+program fptr
+ use funcs
+ use other_fun
+ implicit none
+ procedure(abstract_fun) fun ! Removed INTERFACE
+ pointer(p,fun)
+ type(C_FUNPTR) fp
+
+ fp = get_proc('Hello, world'//achar(0))
+ p = transfer(fp,p)
+ write(*,'(a)') fun([1,2,3])
+end program fptr
+! { dg-final { cleanup-modules "funcs other_fun" } }