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: unassig...@gcc.gnu.org ReportedBy: kwariz....@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.