This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/15397] [g77] c float function called from fortran gives wrong result
- From: "harald dot vogt at desy dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Nov 2004 08:54:14 -0000
- Subject: [Bug target/15397] [g77] c float function called from fortran gives wrong result
- References: <20040512145606.15397.harald.vogt@desy.de>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From harald dot vogt at desy dot de 2004-11-23 08:53 -------
(In reply to comment #0)
> This bug is specific for the x86_64 architecture. On 32 bit architectures it
> does not occur.
>
>
> [lx64 16:27] ~/test/cernlib/x86_64 > gcc -v -save-temps -O test1.f funct2.c
> -lg2c -lfrtbegin
> Reading specs from
>
/afs/ifh.de/@sys/products/gcc/3.4.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/3.4.0/specs
> Configured with: /usr/src/packages/BUILD/gcc-3.4.0/configure
> --prefix=/opt/products/gcc/3.4.0 --enable-shared --enable-cpp
> --enable-threads=posix --enable-languages=c,c++,f77,java
> --with-local-prefix=/opt/products/gcc/3.4.0
> --with-gxx-include-dir=/opt/products/gcc/3.4.0/include/g++-3
> Thread model: posix
> gcc version 3.4.0
>
/afs/ifh.de/@sys/products/gcc/3.4.0/bin/../libexec/gcc/x86_64-unknown-linux-gnu/3.4.0/f771
> test1.f -quiet -dumpbase test1.f -mtune=k8 -auxbase test1 -O -version -o test1.s
> GNU F77 version 3.4.0 (x86_64-unknown-linux-gnu)
> compiled by GNU C version 3.4.0.
> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> as -V -Qy -o test1.o test1.s
> GNU assembler version 2.14.90.0.5 (x86_64-suse-linux) using BFD version
> 2.14.90.0.5 20030722 (SuSE Linux)
>
/afs/ifh.de/@sys/products/gcc/3.4.0/bin/../libexec/gcc/x86_64-unknown-linux-gnu/3.4.0/cc1
> -E -quiet -v -iprefix
> /afs/ifh.de/@sys/products/gcc/3.4.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/3.4.0/
> funct2.c -mtune=k8 -O -o funct2.i
> ignoring nonexistent directory
>
"/afs/ifh.de/@sys/products/gcc/3.4.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/3.4.0/../../../../x86_64-unknown-linux-gnu/include"
> ignoring duplicate directory
> "/opt/products/gcc/3.4.0/lib/gcc/x86_64-unknown-linux-gnu/3.4.0/include"
> ignoring nonexistent directory
>
"/opt/products/gcc/3.4.0/lib/gcc/x86_64-unknown-linux-gnu/3.4.0/../../../../x86_64-unknown-linux-gnu/include"
> #include "..." search starts here:
> #include <...> search starts here:
>
/afs/ifh.de/@sys/products/gcc/3.4.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/3.4.0/include
> /opt/products/gcc/3.4.0/include
> /usr/include
> End of search list.
>
/afs/ifh.de/@sys/products/gcc/3.4.0/bin/../libexec/gcc/x86_64-unknown-linux-gnu/3.4.0/cc1
> -fpreprocessed funct2.i -quiet -dumpbase funct2.c -mtune=k8 -auxbase funct2 -O
> -version -o funct2.s
> GNU C version 3.4.0 (x86_64-unknown-linux-gnu)
> compiled by GNU C version 3.4.0.
> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> as -V -Qy -o funct2.o funct2.s
> GNU assembler version 2.14.90.0.5 (x86_64-suse-linux) using BFD version
> 2.14.90.0.5 20030722 (SuSE Linux)
>
/afs/ifh.de/@sys/products/gcc/3.4.0/bin/../libexec/gcc/x86_64-unknown-linux-gnu/3.4.0/collect2
> --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2
> /usr/lib/../lib64/crt1.o /usr/lib/../lib64/crti.o
>
/afs/ifh.de/@sys/products/gcc/3.4.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/3.4.0/crtbegin.o
>
-L/afs/ifh.de/@sys/products/gcc/3.4.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/3.4.0
> -L/afs/ifh.de/@sys/products/gcc/3.4.0/bin/../lib/gcc
> -L/opt/products/gcc/3.4.0/lib/gcc/x86_64-unknown-linux-gnu/3.4.0
>
-L/afs/ifh.de/@sys/products/gcc/3.4.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/3.4.0/../../../../lib64
>
-L/afs/ifh.de/@sys/products/gcc/3.4.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/3.4.0/../../..
> -L/opt/products/gcc/3.4.0/lib/gcc/x86_64-unknown-linux-gnu/3.4.0/../../../../lib64
> -L/opt/products/gcc/3.4.0/lib/gcc/x86_64-unknown-linux-gnu/3.4.0/../../..
> -L/lib/../lib64 -L/usr/lib/../lib64 test1.o funct2.o -lg2c -lfrtbegin -lgcc
> -lgcc_eh -lc -lgcc -lgcc_eh
>
/afs/ifh.de/@sys/products/gcc/3.4.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/3.4.0/crtend.o
> /usr/lib/../lib64/crtn.o
>
> example code
>
> test1.f:
>
> program test
> *
> * error connected with return value from c routines
> *
> implicit none
> *
> real funct1, funct2, retval
> integer funct3, iretval
>
> * for calling a fortran function
> retval = funct1 (1.1111)
> print *, 'in test1: retval from fortran call is ', retval
> retval = funct2 (1.1111)
> print *, 'in test1: retval from c(float) call is ', retval
> iretval = funct3 (2)
> print *, 'in test1: retval from c(int) call is ', iretval
> stop
>
> end
>
> real function funct1 ( inval )
>
> implicit none
>
> real inval, retval
>
> retval = inval
> print *, 'funct1: return value = ', retval
> funct1 = retval
>
> end
>
> funct2.c:
>
> float funct2_( float* value ) {
> float retval = *value ;
> printf ("funct2: return value = %f\n", retval);
> return retval ;
> }
> int funct3_( int* value ) {
> int retval = *value ;
> printf ("funct2: return value = %d\n", retval);
> return retval ;
> }
>
> Job output:
> [lx64 16:45] ~/test/cernlib/x86_64 > ./a.out
> funct1: return value = 1.11109996
> in test1: retval from fortran call is 1.11109996
> funct2: return value = 1.111100
> in test1: retval from c(float) call is 0.
> funct2: return value = 2
> in test1: retval from c(int) call is 2
(In reply to comment #4)
> (In reply to comment #3)
>
> I checked this with gcc-4.0-20041107 on a ia64, and the problem didn't occur:
>
> $ gfortran -v
> Reading specs from /home/zfkts/lib/gcc/ia64-unknown-linux-gnu/4.0.0/specs
> Configured with: ../gcc-4.0-20041107/configure --prefix=/home/zfkts
> --enable-languages=c,c++,f95
> Thread model: posix
> gcc version 4.0.0 20041107 (experimental)
> $ gfortran -O test1.f funct2.c
> funct2.c: In function 'funct2_':
> funct2.c:3: warning: incompatible implicit declaration of built-in function
'printf'
> funct2.c: In function 'funct3_':
> funct2.c:8: warning: incompatible implicit declaration of built-in function
'printf'
> $ ./a.out
> funct1: return value = 1.111100
> in test1: retval from fortran call is 1.111100
> funct2: return value = 1.111100
> in test1: retval from c(float) call is 1.111100
> funct2: return value = 2
> in test1: retval from c(int) call is 2
> STOP 0
May be the following may give a hint to the g77 developers:
if using the -fno-f2c compile option the error does not occur on AMD64
architectures.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15397