Bug 35662 - [4.3/4.4 regression] gfortran interfaces badly with glibc sincosf() causing breakage
Summary: [4.3/4.4 regression] gfortran interfaces badly with glibc sincosf() causing b...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.3.0
: P4 normal
Target Milestone: 4.3.1
Assignee: Jakub Jelinek
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2008-03-21 23:57 UTC by Kevin McCarty
Modified: 2008-04-16 16:11 UTC (History)
2 users (show)

See Also:
Host: mips-linux-gnu
Target: mips-linux-gnu
Build: mips-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2008-04-15 11:20:07


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin McCarty 2008-03-21 23:57:16 UTC
Hi,

On Debian's mips and mipsel ports, gfortran 4.3 at -O1 or higher generates object code that calls the sincosf() function in glibc's libm.  Unfortunately the function call does not produce the correct result: it returns 0 for the sine and 1 for the cosine.  Since an equivalent C program that uses sincosf() does yield the right results, I conclude that it is gfortran and not libm where the bug occurs -- somehow the call to sincosf() in the generated object code is wrong.  (Not being too knowledgeable on either MIPS or assembly, I unfortunately can't tell you why.  An erroneous assumption about the byte size of the sine and cosine values returned by sincosf(), perhaps?)

This is a regression from gfortran 4.2.3, but the reason is apparently that previous gfortran versions do not generate calls to sincosf().

Version information:

(sid)kmccarty@larsa:~$ gfortran-4.3 -v
Using built-in specs.
Target: mips-linux-gnu
Configured with: ../src/configure linux gnu
Thread model: posix
gcc version 4.3.1 20080309 (prerelease) (Debian 4.3.0-1)

Test case is at http://people.debian.org/~kmccarty/gfortran-sincos-err-mips.tar.gz

The FORTRAN code is "sincos.F", and equivalent C code (I translated the FORTRAN to C by hand) that explicitly uses sincosf() is "sincos.c".

The bad object code is located in subdirectories obj-fail/-O1 and obj-fail/-O2 of the tarball.  Correct object code generated at -O0 is in obj-success/-O0, but may not be that useful for comparison, as the generated assembly with no optimization calls the sinf() and cosf() functions individually.  Output of the FORTRAN and C programs are in "output.txt" and "coutput.txt", respectively, in each subdirectory.

You can quickly regenerate these files with "make output".

best regards,
Kevin McCarty
Comment 1 Jakub Jelinek 2008-04-15 11:20:07 UTC
This is a fortran FE bug.
Comment 2 Jakub Jelinek 2008-04-16 15:57:42 UTC
Subject: Bug 35662

Author: jakub
Date: Wed Apr 16 15:56:58 2008
New Revision: 134349

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134349
Log:
	PR target/35662
	* f95-lang.c (gfc_init_builtin_functions): Make sure
	BUILT_IN_SINCOS{,F,L} types aren't varargs.

	* gfortran.dg/pr35662.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/pr35662.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/f95-lang.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 Jakub Jelinek 2008-04-16 16:06:36 UTC
Subject: Bug 35662

Author: jakub
Date: Wed Apr 16 16:05:51 2008
New Revision: 134352

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134352
Log:
	PR target/35662
	* f95-lang.c (gfc_init_builtin_functions): Make sure
	BUILT_IN_SINCOS{,F,L} types aren't varargs.

	* gfortran.dg/pr35662.f90: New test.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/pr35662.f90
Modified:
    branches/gcc-4_3-branch/gcc/fortran/ChangeLog
    branches/gcc-4_3-branch/gcc/fortran/f95-lang.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 4 Jakub Jelinek 2008-04-16 16:11:06 UTC
Fixed.