[Bug regression/24956] New: Optimizer and uninitialised variables.
s_a_white at email dot com
gcc-bugzilla@gcc.gnu.org
Sun Nov 20 11:21:00 GMT 2005
#include <stdint.h>
#include <stdio.h>
void test (int c)
{
uint8_t a[4] = {0, 1, 2, 3};
uint_least32_t b;
b &= (uint_least32_t) 0xffffff00;
b |= (uint_least32_t) a[3];
b &= (uint_least32_t) 0xffff00ff;
b |= (uint_least32_t) (a[2] << 8);
b &= (uint_least32_t) 0xff00ffff;
b |= (uint_least32_t) (a[1] << 16);
b &= (uint_least32_t) 0x00ffffff;
b |= (uint_least32_t) (a[0] << 24);
printf ("b=%08x\n", b);
if (c)
{
printf ("here\n");
b = ~0;
printf ("here2\n");
}
printf ("b=%08x\n", b);
}
int main ()
{
test (0);
return 0;
}
Output of gcc -O0 bug.cpp -o bug -lstdc++ is:
b=00010203
b=00010203
Output of gcc -O2 bug.cpp -o bug -lstdc++ is:
b=00010203
b=ffffffff
Doing either of these obtains the correct output:
- uint_least32_t b;
+ uint_least32_t b = 0;
or
- b = ~0;
System: Fresh install of Mandriva Linux Free 2006.0 with all
patches applied as of 19/11/2005
gcc -v reports:
Using built-in specs.
Target: i586-mandriva-linux-gnu
Configured with: ../configure --prefix=/usr --libexecdir=/usr/lib
--with-slibdir=/lib --mandir=/usr/share/man --infodir=/usr/share/info
--enable-shared --enable-threads=posix --disable-checking
--enable-languages=c,c++,ada,f95,objc,java --host=i586-mandriva-linux-gnu
--with-system-zlib --enable-long-long --enable-__cxa_atexit
--enable-clocale=gnu --disable-libunwind-exceptions --enable-java-awt=gtk
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --enable-gtk-cairo
--disable-libjava-multilib
Thread model: posix
gcc version 4.0.1 (4.0.1-5mdk for Mandriva Linux release 2006.0)
--
Summary: Optimizer and uninitialised variables.
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: regression
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: s_a_white at email dot com
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24956
More information about the Gcc-bugs
mailing list