This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/40962] New: [4.5.0,4.4.0,4.3.2] conversion problem for f-allocatable -> cptr -> fptr -> f-allocatable
- From: "reuter at physik dot uni-freiburg dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 4 Aug 2009 14:23:46 -0000
- Subject: [Bug fortran/40962] New: [4.5.0,4.4.0,4.3.2] conversion problem for f-allocatable -> cptr -> fptr -> f-allocatable
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following test code below (which works with the NAG 5.2 Fortran Compiler)
seems to choke over the conversion f-allocatable -> cptr -> fptr ->
f-allocatable. With NAG the output should be:
--------------------------------------------------
nagfor tab3.f90 -o tab3 && ./tab3
NAG Fortran Compiler Release 5.2(686)
[NAG Fortran Compiler normal termination]
In: 1 2 3 4 5 6 -1 -2 -3 -4 -5 -6
Tmp: 1 2 3 4 5 6 -1 -2 -3 -4 -5 -6
Out: 1 2 3 4 5 6 -1 -2 -3 -4 -5 -6
-------------------------------------------------
For gfortran 4.5.0 the result is:
In: 1 2 3 4 5 6 -1 -2 -3 -4 -5 -6
Tmp: 1 2 3 -1 -2 -3 -1 -2 -3 -4 -5 -6
Out: 1 2 3 -1 -2 -3 -4 -5 -6 0 0 0
while for gfortran 4.3.2 the result is:
-------------------------------------------------
In: 1 2 3 4 5 6 -1 -2 -3 -4 -5 -6
Tmp: 1 2 3 -1 -2 -3 -1 -2 -3 -4 -5 -6
Out: 1 2 3 -1 -2 -3 -4 -5 -6 ** ** 0
It looks as if the order of indices gets confused by gfortran in changing the
corresponding pointers. According to the F2003 Handbook this code should be
allowed.
TEST PROGRAM:
----------------------------------------------------------
program main
use iso_c_binding
implicit none
character(*), parameter :: fmt = "(A,40(1x,I2))"
integer, parameter :: n1 = 2
integer, parameter :: n2 = 3
integer, parameter :: n3 = 2
integer, dimension(2), parameter :: shape2 = (/ n1, n2 /)
integer, dimension(3), parameter :: shape3 = (/ n1, n2, n3 /)
integer, dimension(n1, n2), parameter :: &
c0001 = reshape ( (/ 1, 2, 3, 4, 5, 6 /), shape2)
integer, dimension(n1, n2), parameter :: &
c0002 = reshape ( (/ -1,-2, -3,-4, -5,-6 /), shape2)
integer, dimension(n1, n2, n3), parameter :: &
table_in = reshape ( (/ c0001, c0002 /), shape3)
integer, dimension(:,:,:), allocatable, target :: table_out
print fmt, "In: ", table_in
! Allocate table_out with shape=shape3
allocate (table_out (n1, n2, n3))
! Set table_out via a C pointer
call set_table (c_loc (table_out))
print fmt, "Out:", table_out
contains
subroutine set_table (cptr)
type(c_ptr), intent(in) :: cptr
integer, dimension(:,:,:), pointer :: table_tmp
! This should make table_tmp an alias to table_out
call c_f_pointer (cptr, table_tmp, shape3)
! Now set the value of table_tmp
table_tmp = table_in
print fmt, "Tmp:", table_tmp
end subroutine set_table
end program main
--------------------------------------------------
--
Summary: [4.5.0,4.4.0,4.3.2] conversion problem for f-
allocatable -> cptr -> fptr -> f-allocatable
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: reuter at physik dot uni-freiburg dot de
GCC build triplet: 4.5.0 Ref. svn r
GCC host triplet: Linux 32bit, 64bit, MAC OS X
GCC target triplet: gcc, gfortran 4.3.2, 4.4.0, 4.5.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40962