[Bug fortran/19561] New: [gfortran] wrong code generation for pointers to derived types
martin at mpa-garching dot mpg dot de
gcc-bugzilla@gcc.gnu.org
Fri Jan 21 10:30:00 GMT 2005
When compiling the following code with current gfortan, the resulting executable
produces the following output:
number, derived = 2
number, simple = 1
number, simple = *****
The (IMO) correct output would be
number, derived = 2
number, simple = 1
number, simple = 1
which is produced by most other compilers I tried.
Only Intel ifc 8.0 and 8.1 produce the same output as
gfortran.
module simpleObj
implicit none
type objA
private
integer :: i
end type objA
interface new
module procedure oaInit
end interface
interface print
module procedure oaPrint
end interface
private
public objA,new,print
contains
subroutine oaInit(oa,i)
integer :: i
type(objA) :: oa
oa%i=i
end subroutine oaInit
subroutine oaPrint(oa)
type(objA) :: oa
print '("number, simple = ",i5)', oa%i
end subroutine oaPrint
end module simpleObj
! -----------------------------------------------------------------
module derivedObj
use simpleObj
implicit none
type objB
private
integer :: i
type(objA), pointer :: oa
end type objB
interface new
module procedure obInit
end interface
interface print
module procedure obPrint
end interface
private
public objB,new,print,getOa
contains
subroutine obInit(ob,oa,i)
integer :: i
type(objA), target :: oa
type(objB) :: ob
ob%i=i
ob%oa=>oa
end subroutine obInit
subroutine obPrint(ob)
type(objB) :: ob
print '("number, derived = ",i5)', ob%i
call print(ob%oa)
end subroutine obPrint
function getOa(ob) result(oa)
type(objB),target :: ob
type(objA), pointer :: oa
oa=>ob%oa
end function getOa
end module derivedObj
! -----------------------------------------------------------------
program test
use simpleObj
use derivedObj
implicit none
type(objA),target :: oa
type(objB),target :: ob
call new(oa,1)
call new(ob,oa,2)
call print(ob)
call print(getOa(ob))
end program test
~/tmp>gfortran -v test.f90
Driving: gfortran -v test.f90 -lgfortranbegin -lgfortran -lm -shared-libgcc
Using built-in specs.
Configured with: /scratch/gcc/configure --quiet
--prefix=/afs/mpa/data/martin/ugcc --enable-languages=c++,f95
--with-gmp=/afs/mpa/data/martin/mygmp
Thread model: posix
gcc version 4.0.0 20050120 (experimental)
/afs/mpa/data/martin/ugcc/libexec/gcc/i686-pc-linux-gnu/4.0.0/f951 test.f90
-quiet -dumpbase test.f90 -mtune=pentiumpro -auxbase test -version -o
/tmp/ccZa4zwg.s
GNU F95 version 4.0.0 20050120 (experimental) (i686-pc-linux-gnu)
compiled by GNU C version 4.0.0 20050120 (experimental).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
as -V -Qy -o /tmp/cc0LLrQq.o /tmp/ccZa4zwg.s
GNU assembler version 2.14 (i686-pc-linux-gnu) using BFD version 2.14 20030612
/afs/mpa/data/martin/ugcc/libexec/gcc/i686-pc-linux-gnu/4.0.0/collect2
--eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o
/usr/lib/crti.o
/afs/mpa/data/martin/ugcc/lib/gcc/i686-pc-linux-gnu/4.0.0/crtbegin.o
-L/afs/mpa/data/martin/ugcc/lib/gcc/i686-pc-linux-gnu/4.0.0
-L/afs/mpa/data/martin/ugcc/lib/gcc/i686-pc-linux-gnu/4.0.0/../../..
/tmp/cc0LLrQq.o -lgfortranbegin -lgfortran -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/afs/mpa/data/martin/ugcc/lib/gcc/i686-pc-linux-gnu/4.0.0/crtend.o /usr/lib/crtn.o
~/tmp>./a.out
number, derived = 2
number, simple = 1
number, simple = *****
--
Summary: [gfortran] wrong code generation for pointers to derived
types
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: martin at mpa-garching dot mpg dot de
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19561
More information about the Gcc-bugs
mailing list