http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60062
Bug ID: 60062
Summary: wrong code (for code with the optimize attribute) at
-O1 and above on x86_64-linux-gnu in 32-bit mode
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ipa
Assignee: unassigned at gcc dot gnu.org
Reporter: su at cs dot ucdavis.edu
The current gcc trunk miscompiles the following code that uses the optimize
attribute on x86_64-linux at -O1 and above in 32-bit mode (but not 64-bit).
This is a regression from 4.8.x.
It also affects 4.7.x and 4.6.x.
$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-trunk/configure --prefix=/usr/local/gcc-trunk
--enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
gcc version 4.9.0 20140204 (experimental) [trunk revision 207452] (GCC)
$
$ gcc-trunk -m32 -O0 small.c; a.out
hello
$ gcc-trunk -m64 -O1 small.c; a.out
hello
$ gcc-4.8 -m32 -O1 small.c; a.out
hello
$
$ gcc-trunk -m32 -O1 small.c; a.out
Segmentation fault (core dumped)
$ gcc-4.7 -m32 -O1 small.c; a.out
Segmentation fault (core dumped)
$ gcc-4.6 -m32 -O1 small.c; a.out
Segmentation fault (core dumped)
$
----------------------------------
int printf(const char *, ...);
int a;
static void
foo(const char *p1, int p2)
{
printf("%s\n", p1);
}
__attribute__((optimize(0)))
int
main()
{
foo("hello", a);
return 0;
}