This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/29605] New: [4.0 Regression] optimization breaks global variable affectation
- From: "clement dot vasseur at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 26 Oct 2006 16:47:52 -0000
- Subject: [Bug c/29605] New: [4.0 Regression] optimization breaks global variable affectation
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following code does not produce the same result when compiled with
optimization.
Looking at the generated assembler code, it looks like the "value = 0"
affectation in the "test" function is not emitted when using -Os, -O1 and -O2.
It works fine with -O0 and -O3.
----------------------
int value = 0;
void modify(int arg)
{
if (arg != 42)
return;
value = 1;
}
void test(void)
{
if (value)
return;
modify(42);
value = 0;
}
int main(void)
{
test();
return value;
}
----------------------
Usage:
$ gcc -O0 test.c ; ./a.out ; echo $?
0
$ gcc -O1 test.c ; ./a.out ; echo $?
1
More information about the gcc build:
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,java,f95
--prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.0 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-awt=gtk-default --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr
--enable-checking=release x86_64-linux-gnu
Thread model: posix
gcc version 4.0.4 20060630 (prerelease) (Ubuntu 4.0.3-4)
GCC versions 3.4.6 and 4.1.1 appear to work fine.
--
Summary: [4.0 Regression] optimization breaks global variable
affectation
Product: gcc
Version: 4.0.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: clement dot vasseur at gmail dot com
GCC build triplet: x86_64-linux-gnu
GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29605