Bug#179712: gcc-3.2 -O2 miscompilation (i386)
Package: gcc-3.2
Version: 1:3.2.2-0pre8
Severity: normal
gcc-3.2 -O2 miscompiles following program:
---------------------------------------------
extern int write(int fd, void *buf, int len);
extern int toupper(int c);
void strupr (char *s)
{
while (*s)
*s++ = toupper(*s);
}
int main(int argc, char *argv[])
{
char s[] = "foo";
strupr(s);
write(1, s, 3);
write(1, "\n", 1);
return 0;
}
---------------------------------------------
$ gcc-3.2 -Wall -O2 -o test test.c
test.c: In function `strupr':
test.c:7: warning: operation on `s' may be undefined
$ ./test
OO
$
---------------------------------------------
gcc-2.95 compiles it correctly, also gcc-3.2 when optimizing
less than -O2. When the "toupper(*s)" is replaced with "*s & 0x5f"
gcc-3.2 -O2 also works and without warning.
found the error when tried to compile glheretic.
-- System Information:
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux snoopy 2.4.20 #1 SMP Mon Jan 13 17:12:00 EET 2003 i686
Locale: LANG=C, LC_CTYPE=C
Versions of packages gcc-3.2 depends on:
ii binutils 2.13.90.0.16-1 The GNU assembler, linker and bina
ii cpp-3.2 1:3.2.2-0pre8 The GNU C preprocessor
ii gcc-3.2-base 1:3.2.2-0pre8 The GNU Compiler Collection (base
ii libc6 2.3.1-10 GNU C Library: Shared libraries an
ii libgcc1 1:3.2.2-0pre8 GCC support library
-- no debconf information
Reply to: