Incorrect optimized code generated by current CVS snapshot
James A. Bednar
jbednar@cs.utexas.edu
Wed May 10 22:00:00 GMT 2000
Using the g++ from the 20000504 CVS snapshot RPMs obtained from
http://www.codesourcery.com/gcc-snapshots.html , the following code
prints garbage when compiled using "-O2" but works fine in all other
C++ compiler cases tested: "-O1", no optimization, other g++ versions,
other C++ compilers, etc.:
#include <stdio.h>
void F(const char **sp)
{ printf("%s\n",*sp); }
void G(const char* s)
{ F(&s); }
int main(int, char)
{ G("TestString"); }
Here's the output from a working compiler on a Pentium III:
linux> /usr/bin/g++ -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.95.2/specs
gcc version 2.95.2 19991024 (release)
linux> /usr/bin/g++ -O2 bug12.c
linux> ./a.out
TestString
Here's the output from the current snapshot on the same machine:
linux> /usr/local/bin/g++ -v
Reading specs from /usr/local/bin/../lib/gcc-lib/i386-pc-linux-gnu/2.96/specs
gcc version 2.96 20000504 (experimental)
linux> /usr/local/bin/g++ -O2 bug12.c
linux> ./a.out
????$\227^D^H^A
I've transliterated the garbage output above into how it appears in an
Emacs buffer; the output consists of binary characters, so it would
have printed differently on different terminals and wouldn't have
survived email anyway.
Here's the output from the snapshot's C compiler on the same machine:
linux> /usr/local/bin/gcc -v
Reading specs from /usr/local/bin/../lib/gcc-lib/i386-pc-linux-gnu/2.96/specs
gcc version 2.96 20000504 (experimental)
linux> /usr/local/bin/gcc -O2 bug12.c
bug12.c: In function `main':
bug12.c:9: parameter name omitted
bug12.c:9: parameter name omitted
linux> ./a.out
????$\227^D^H^A
Oddly, the garbage disappears if I add names for the main()
parameters, which is why I present the g++ output, since in C++ it
should be legal to omit the names of these unused parameters.
In case this code proves useful as a test case, I hereby place it into
the public domain for anyone to use for any purpose whatsoever.
Jim Bednar
More information about the Gcc-bugs
mailing list