gcc 2.95.2 bug: -O2 -g
Rajeev Byrisetty
RajeevB@Zambeel.com
Thu Feb 22 13:27:00 GMT 2001
I see the following optimization bug. I have reduced it a really small
program as below. The compiler is adding code that corrupts the caller's
stack. The same code (along with a few more instructions) is absent when
compiled with O1.
I am only seeing it in a couple of test programs that have a variant of this
"showtimes" function. Note that removing a variety of things (such as
unsigned int -> int, removing sysconf, removing the printfs) gets rid of the
problem.
offending instruction: 0x80487f3
<<o2bug.c>>
Compiler details:
version: 2.95.2
compiler options: -O2 -g
----------------------------------------
]$ gdb ./o2bug
GNU gdb 19991004
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux"...
(gdb) disas showtimes
Dump of assembler code for function showtimes:
0x80487e0 <showtimes>: push %ebp
0x80487e1 <showtimes+1>: mov %esp,%ebp
0x80487e3 <showtimes+3>: sub $0x40,%esp
0x80487e6 <showtimes+6>: push %edi
0x80487e7 <showtimes+7>: push %esi
0x80487e8 <showtimes+8>: mov 0xc(%ebp),%edi
0x80487eb <showtimes+11>: mov 0x10(%ebp),%eax
0x80487ee <showtimes+14>: xor %edx,%edx
0x80487f0 <showtimes+16>: mov %eax,0x10(%ebp)
0x80487f3 <showtimes+19>: mov %edx,0x14(%ebp)
0x80487f6 <showtimes+22>: add $0xfffffff4,%esp
0x80487f9 <showtimes+25>: push $0x2
0x80487fb <showtimes+27>: call 0x80486ac <sysconf>
0x8048800 <showtimes+32>: mov %eax,%ecx
0x8048802 <showtimes+34>: mov $0x3e8,%edx
0x8048807 <showtimes+39>: mov %edx,%eax
0x8048809 <showtimes+41>: cltd
0x804880a <showtimes+42>: idiv %ecx,%eax
0x804880c <showtimes+44>: mov 0x10(%ebp),%edx
0x804880f <showtimes+47>: mov %eax,%esi
0x8048811 <showtimes+49>: add $0xfffffff8,%esp
0x8048814 <showtimes+52>: push %edx
---Type <return> to continue, or q <return> to quit---q
-------------- next part --------------
A non-text attachment was scrubbed...
Name: o2bug.c
Type: text/x-c
Size: 610 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20010222/acbba31d/attachment.bin>
More information about the Gcc-bugs
mailing list