Bug 55695 - Miscompilation of pow() & sqrt() using musl libc
Summary: Miscompilation of pow() & sqrt() using musl libc
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-14 19:44 UTC by ojab
Modified: 2012-12-18 12:45 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Preprocessed source (4.97 KB, application/octet-stream)
2012-12-14 19:44 UTC, ojab
Details
Kinda reduced testcase (413 bytes, text/plain)
2012-12-14 19:46 UTC, ojab
Details
Correct kinda reduced testcase (421 bytes, application/octet-stream)
2012-12-14 21:05 UTC, ojab
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ojab 2012-12-14 19:44:58 UTC
Created attachment 28966 [details]
Preprocessed source

I'm trying to build spandsp using musl libc and found that sqrt() & pow() compilation is broken when using <tgmath.h> with gcc-4.8, but no errors with gcc-4.2.4.
Preprocessed source are the same using both gcc versions (can be found in the attached file).
According to the one of the musl developers, it can be related to the "tgmath __RETCAST magic" http://www.openwall.com/lists/musl/2012/12/14/6
musl's tgmath.h source can be found at http://git.musl-libc.org/cgit/musl/tree/include/tgmath.h

/bin/sh ../libtool --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I..  -I/usr/include/libxml2 -DNDEBUG -msse2 -Wunused-but-set-variable -std=gnu99 -ffast-math -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -fvisibility=hidden -DHAVE_VISIBILITY=1  -pedantic -MT awgn.lo -MD -MP -MF .deps/awgn.Tpo -c -o awgn.lo awgn.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -I/usr/include/libxml2 -DNDEBUG -msse2 -Wunused-but-set-variable -std=gnu99 -ffast-math -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -fvisibility=hidden -DHAVE_VISIBILITY=1 -pedantic -MT awgn.lo -MD -MP -MF .deps/awgn.Tpo -c awgn.c  -fPIC -DPIC -o .libs/awgn.o
awgn.c: In function 'awgn_init_dbov':
awgn.c:109:5: error: void value not ignored as it ought to be
     s->rms = pow(10.0, level/20.0)*32768.0;
     ^
awgn.c: In function 'awgn':
awgn.c:165:9: error: void value not ignored as it ought to be
         fac = sqrt(-2.0*log(r)/r);
         ^
awgn.c:165:9: error: void value not ignored as it ought to be
awgn.c:165:9: error: void value not ignored as it ought to be
awgn.c:165:9: error: void value not ignored as it ought to be



Please tell me if any other info is needed.
Comment 1 ojab 2012-12-14 19:46:22 UTC
Created attachment 28967 [details]
Kinda reduced testcase
Comment 2 ojab 2012-12-14 21:05:21 UTC
Created attachment 28970 [details]
Correct kinda reduced testcase

oops, testcase hasn't actually shown the issue.
Just confirmed that the issue also exist with glibc/x86_64 [gcc (GCC) 4.8.0 20121209 (experimental), last snapshot]
Comment 3 Andrew Pinski 2012-12-14 21:37:45 UTC
I think one of the typeof is being chosen as a void* and then we take another typeof of the deferenced version of that.  This is what is causing the "void value not ignored as it ought to be".
Comment 4 ojab 2012-12-15 22:18:28 UTC
Bisection told me that

a75b1c712f1eaddc69919461ead67f4ac21663fe is the first bad commit
commit a75b1c712f1eaddc69919461ead67f4ac21663fe
Author: jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Sun Mar 29 18:13:43 2009 +0000

    	PR c/456
    	PR c/5675
    	PR c/19976
    	PR c/29116
    	PR c/31871
    	PR c/35198
…
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@145254 138bc75d-0d04-0410-961f-82ee72b054a4


Adding author to CC.
Comment 5 ojab 2012-12-18 12:45:57 UTC
Closing per http://www.openwall.com/lists/musl/2012/12/18/6