This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/50612] C_FUNLOC takes the wrong address (result variable not function address)
- From: "burnus at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 04 Oct 2011 15:25:54 +0000
- Subject: [Bug fortran/50612] C_FUNLOC takes the wrong address (result variable not function address)
- Auto-submitted: auto-generated
- References: <bug-50612-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50612
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |janus at gcc dot gnu.org
--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-10-04 15:25:54 UTC ---
The (cf. below) program is accepted by ifort and PGI (and, was written, by
gfortran) - but it segfaults at run time.
The program is rejected by g95 and Crayftn with:
Error: 'x' argument of 'c_funloc' intrinsic at (1) must be PROCEDURE
or
This actual argument is not a program unit
[I still have not checked the standard, but I am inclined to think that the
programs are invalid - and should be rejected.]
* * *
Similar issue with proc pointers:
integer function foo()
procedure(), pointer :: ptr
ptr => foo
foo = 7
end function foo
With gfortran:
It compiles - and takes the result variable as address.
With g95:
It compiles.
With ifort:
error #8191: The procedure target must be a procedure or a procedure pointer.
With Crayftn:
Invalid proc-target for this procedure pointer assignment statement.
With PGI:
PGF90-S-0084-Illegal use of symbol foo - must have the TARGET or
POINTER attribute
* * *
Extended version of the program of comment 0:
module m
contains
integer function foo(i, fptr) bind(C)
use iso_c_binding
implicit none
integer :: i
type(c_funptr) :: fptr
fptr = c_funloc(foo) ! takes adress of result variable!
foo = 42*i
end function foo
end module m
use iso_c_binding
use m
implicit none
type(c_funptr) :: fp, fp2
procedure(integer), pointer :: func
print *, foo(1, fp)
call C_F_PROCPOINTER(fp, func)
print *, func(2, fp2)
end