This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
gcc optimisation bug
- To: gcc-bugs at gcc dot gnu dot org
- Subject: gcc optimisation bug
- From: Erik Sandberg <erik dot sandberg at euroseek dot net>
- Date: Mon, 17 Jan 2000 17:43:57 +0100
I have found a GCC bug.
Attached is a program showing it. The original program was written for a
programming competition, in which one of the exercises was to write a
program that played a solitaire card game. It was quite hard to isolate the
bug, so the example I have here is still about a deck of cards. I hope it
isn't too hard to read.
The program works fine with -O0, -O1 and -Os, but not with -O2 or -O3.
Output with -O0:
51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27
26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02
01 00
Output with -O2:
51 38 25 12
I have tested it both with gcc 2.951 and 2.952, it occurs on both. I am
using DJGPP 2.02 under win98 dos shell. CPU: AMD K6 (i386 compatible).
I am using the DOS binaries from simtelnet (/gnu/djgpp/v2gnu/).
Compiler options
Giving bad code:
gcc -g3 -O3 uppg5.c
gcc -g3 -O2 uppg5.c
Giving correct code:
gcc -g3 -Os uppg5.c
gcc -g3 -O1 uppg5.c
gcc -g3 -O0 uppg5.c
gcc -g3 uppg5.c
This bug ate half an hour of my competition time, but it didn't matter (I
won it anyways).
And btw, thanks for a great compiler. I'm sure any other compiler would
have created many more unintentional bugs (I do mean it, my experience
shows one gcc bug after more than 3 years of almost daily usage, and while
I was obliged to work with VC6 for a few weeks, I found about 1 bug/day
which I had to work around).
Erik
uppg5.tar.bz2