Bug#288721: gcc-3.3: gcc produces wrong code with -O1 or -O2 for very simple C program (included)
Package: gcc-3.3
Version: 1:3.3.5-5
Severity: important
When compiling the included program with the mentioned versions of gcc,
wrong code is generated when using -O1 or -O2. See the comments in the
program, which I saved as test.c:
---------------------- CUT HERE -----------------------
/* This small program shows a bug in the optimizer of gcc.
* It occurs at least in these versions:
* - gcc (GCC) 3.3.4 (Debian 1:3.3.4-13)
* - gcc (GCC) 3.3.5 (Debian 1:3.3.5-5)
* It does not occur when the body of f is put directly in main.
* It does not occur when the "if" is split into two "if"s.
* It does not occur when -O0 or -O3 (or higher) is used.
* It only occurs if -O1 or -O2 are used.
* Output on my system with gcc (GCC) 3.3.5 (Debian 1:3.3.5-5):
* $ gcc test.c -o testbug
* $ ./testbug
* Address 0xff00 NOT in [0x4000,0xc000> (CORRECT)
* $ gcc test.c -o testbug -O1
* $ ./testbug
* Address 0xff00 in [0x4000,0xc000> (WRONG)
*/
#include <stdio.h>
void f(unsigned short ad)
{
if (ad >= 0x4000 && ad < 0xc000)
printf("Address 0x%x in [0x4000,0xc000> (WRONG)\n", ad);
else
printf("Address 0x%x NOT in [0x4000,0xc000> (CORRECT)\n", ad);
}
int main (void)
{
f(0xff00);
return 0;
}
---------------------- CUT HERE -----------------------
This bug may already be reported, but at least I couldn't find it back
in the list.
-- System Information:
Debian Release: 3.1
APT prefers testing
APT policy: (500, 'testing')
Architecture: i386 (i686)
Kernel: Linux 2.6.8-1-k7
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Versions of packages gcc-3.3 depends on:
ii binutils 2.15-5 The GNU assembler, linker and bina
ii cpp-3.3 1:3.3.5-5 The GNU C preprocessor
ii gcc-3.3-base 1:3.3.5-5 The GNU Compiler Collection (base
ii libc6 2.3.2.ds1-20 GNU C Library: Shared libraries an
ii libgcc1 1:3.4.3-6 GCC support library
-- no debconf information
Reply to: