public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/53079] New: Unwanted optimization occurs on function with the same name as a math.h function without including math.h nor linking with libm
@ 2012-04-22 23:59 kwariz.dvp at gmail dot com
  2012-04-23  1:20 ` [Bug c/53079] " pinskia at gcc dot gnu.org
  2012-04-23 10:28 ` rguenth at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: kwariz.dvp at gmail dot com @ 2012-04-22 23:59 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53079

             Bug #: 53079
           Summary: Unwanted optimization occurs on function with the same
                    name as a math.h function without including math.h nor
                    linking with libm
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: kwariz.dvp@gmail.com


Created attachment 27218
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27218
test.i output but with #include <stdio.h> commented in test.c

A math function optimization is triggered when a function has the same name as
a math function, even if no link against libm is asked for.

This error occurs only when using the gcc front end, g++ produces a correct
code.

==== test.c
#include <stdio.h>

double floor(double x)
{
  return 3.14;
}

int main()
{
  double x;
  x=1.1;

  printf("floor(%lf)=%lf\n", 1.1, floor(1.1));
  printf("floor(%lf)=%lf\n", x, floor(x));

  return 0;
}

==== compile and run

> gcc -Wall -Wextra -v -save-temps -o test test.c 
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/4.6/lto-wrapper
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,objc,fortran,obj-c++,java,ada
--enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.6
--enable-ssp --disable-libssp --disable-plugin
--with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux'
--disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib
--enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch
--enable-version-specific-runtime-libs --program-suffix=-4.6
--enable-linux-futex --without-system-libunwind --with-arch-32=i586
--with-tune=generic --build=x86_64-suse-linux
Thread model: posix
gcc version 4.6.2 (SUSE Linux) 
COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-v' '-save-temps' '-o' 'test'
'-mtune=generic' '-march=x86-64'
 /usr/lib64/gcc/x86_64-suse-linux/4.6/cc1 -E -quiet -v test.c -mtune=generic
-march=x86-64 -Wall -Wextra -fpch-preprocess -o test.i
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib64/gcc/x86_64-suse-linux/4.6/include
 /usr/local/include
 /usr/lib64/gcc/x86_64-suse-linux/4.6/include-fixed
 /usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/include
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-v' '-save-temps' '-o' 'test'
'-mtune=generic' '-march=x86-64'
 /usr/lib64/gcc/x86_64-suse-linux/4.6/cc1 -fpreprocessed test.i -quiet
-dumpbase test.c -mtune=generic -march=x86-64 -auxbase test -Wall -Wextra
-version -o test.s
GNU C (SUSE Linux) version 4.6.2 (x86_64-suse-linux)
        compiled by GNU C version 4.6.2, GMP version 5.0.2, MPFR version 3.0.1,
MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C (SUSE Linux) version 4.6.2 (x86_64-suse-linux)
        compiled by GNU C version 4.6.2, GMP version 5.0.2, MPFR version 3.0.1,
MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: eb9bdda5160103bdfd1958724e664f28
test.c: In function ‘floor’:
test.c:3:21: warning: unused parameter ‘x’ [-Wunused-parameter]
COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-v' '-save-temps' '-o' 'test'
'-mtune=generic' '-march=x86-64'
 /usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/bin/as --64
-o test.o test.s
COMPILER_PATH=/usr/lib64/gcc/x86_64-suse-linux/4.6/:/usr/lib64/gcc/x86_64-suse-linux/4.6/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/4.6/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/bin/
LIBRARY_PATH=/usr/lib64/gcc/x86_64-suse-linux/4.6/:/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/lib/:/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-v' '-save-temps' '-o' 'test'
'-mtune=generic' '-march=x86-64'
 /usr/lib64/gcc/x86_64-suse-linux/4.6/collect2 --build-id --eh-frame-hdr -m
elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o test
/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../lib64/crt1.o
/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../lib64/crti.o
/usr/lib64/gcc/x86_64-suse-linux/4.6/crtbegin.o
-L/usr/lib64/gcc/x86_64-suse-linux/4.6
-L/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../lib64 -L/lib/../lib64
-L/usr/lib/../lib64
-L/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/lib
-L/usr/lib64/gcc/x86_64-suse-linux/4.6/../../.. test.o -lgcc --as-needed
-lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed
/usr/lib64/gcc/x86_64-suse-linux/4.6/crtend.o
/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../lib64/crtn.o


> ./test
floor(1.100000)=1.000000
floor(1.100000)=3.140000

====

double floor(double) returns unconditionally the value 3.14, so the first call
has been wrongly optimized using a <math.h> floor call.
This error occurs only when using the gcc front end, g++ produces a correct
code.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/53079] Unwanted optimization occurs on function with the same name as a math.h function without including math.h nor linking with libm
  2012-04-22 23:59 [Bug c/53079] New: Unwanted optimization occurs on function with the same name as a math.h function without including math.h nor linking with libm kwariz.dvp at gmail dot com
@ 2012-04-23  1:20 ` pinskia at gcc dot gnu.org
  2012-04-23 10:28 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-04-23  1:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53079

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-04-23 01:19:48 UTC ---
This is expected.  If you don't want floor to be considered a builtin, then use
-fno-builtin-floor .  The C standard even says the name is in the reversed
namespace really.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/53079] Unwanted optimization occurs on function with the same name as a math.h function without including math.h nor linking with libm
  2012-04-22 23:59 [Bug c/53079] New: Unwanted optimization occurs on function with the same name as a math.h function without including math.h nor linking with libm kwariz.dvp at gmail dot com
  2012-04-23  1:20 ` [Bug c/53079] " pinskia at gcc dot gnu.org
@ 2012-04-23 10:28 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-04-23 10:28 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53079

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-04-23 10:27:13 UTC ---
Indeed.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-04-23 10:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-22 23:59 [Bug c/53079] New: Unwanted optimization occurs on function with the same name as a math.h function without including math.h nor linking with libm kwariz.dvp at gmail dot com
2012-04-23  1:20 ` [Bug c/53079] " pinskia at gcc dot gnu.org
2012-04-23 10:28 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).