This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
optimization bug
- From: Calin Cascaval <cascaval at us dot ibm dot com>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 4 Jan 2002 09:21:39 -0500 (EST)
- Subject: optimization bug
- Reply-to: cascaval at us dot ibm dot com
The following program gives the wrong result when compiled with optimizations.
The correct output is shown for the non-optimized version.
I have seen the behavior on several machines running RedHat Linux 7.1 and 7.2.
Also, I have tried with two versions of gcc (2.95.3 and 2.96). Same behavior.
/* ---------- machine ----------------------------- */
gccbug> uname -a
Linux pongo.watson.ibm.com 2.4.17 #1 Thu Dec 27 16:55:39 EST 2001 i686 unknown
/* ---------- gcc --------------------------------- */
gccbug> /usr/local/bin/gcc -v
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/specs
gcc version 2.95.3 20010315 (release)
GCC configure options:
--prefix=/usr/local --enable-languages=c++,c
/* ------ ceil.c ----------------- */
#include <math.h>
#include <stdio.h>
int main()
{
printf("%d:%d\n%d:%d\n%d:%d\n",
16, (int)ceil(log(16)/log(2)),
32, (int)ceil(log(32)/log(2)),
64, (int)ceil(log(64)/log(2)));
return 0;
}
/* --------------- output ------------------ */
gccbug> /usr/local/bin/gcc ceil.c -lm
gccbug> a.out
16:4
32:5
64:6
gccbug> /usr/local/bin/gcc -O3 ceil.c -lm
gccbug> a.out
16:4
32:6
64:6
gccbug> /usr/local/bin/gcc -O2 ceil.c -lm
gccbug> a.out
16:4
32:6
64:6
gccbug> /usr/local/bin/gcc -O1 ceil.c -lm
gccbug> a.out
16:4
32:6
64:6
Calin Cascaval
IBM TJ Watson Research Center
(914)-945-2635
cascaval@us.ibm.com