This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ABI mismatch for single precision floating point return between C and Fortran


Gerhard Tonn wrote:

> when I compile and link the following two small programs on the S/390
> architecture, I get a wrong result from the C function. This is caused by the
> fact that according to the ABI on S/390 a float is returned as single
> precision float, but Fortran expects that it is returned as double (that is
> what the assembler says).

Doh !  It's certainly not what the Fortran code says ... SDOTTESTC is an
implicitly typed function (type REAL), so it should match a float
function in C.

> Does anyone know, if this is somehow tied to Fortran or if I can change this
> behaviour by any backend switches. The problem occurs with 2.95.4, 3.0.4 and
> the latest 3.1 snapshot.

As far as I can see, if your analysis is correct, this is a bug.  I
don't know yet which part of the compiler is to blame, but it is not
correct.

> Btw, the same problem seems to appear on sparc.

Yes, I recall (now that I see this example) that we had an earlier GNATS
report that had a similar problem on sparc (don't know the number
off-hand).

>       PROGRAM         TST
> *     .. Parameters ..
>       INTEGER         NOUT
>       PARAMETER       (NOUT=6)
>       REAL            EC
> *     .. External Subroutines ..
>       EXTERNAL        SDOTTESTC
> 
>       EC=SDOTTESTC()
> 
>       WRITE (NOUT,99997) EC
>       RETURN
> 99997 FORMAT(2E12.4)
>       END
> 
> float
> sdottestc_()
> {
>   float e = 1.34;
>   printf("%e\n", e);
>   return e;
> }

I'll look into it this weekend (provided I can reproduce it on one of
the targets I have at home: i686-*-linux-gnu, alphaev6-*-linux-gnu or
powerpc-*-linux-gnu).

Thanks for the analysis !

-- 
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]