From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11280 invoked by alias); 15 Jul 2009 06:33:13 -0000 Received: (qmail 11160 invoked by uid 48); 15 Jul 2009 06:32:59 -0000 Date: Wed, 15 Jul 2009 06:33:00 -0000 Subject: [Bug c/40762] New: possible integer miscompilation X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "regehr at cs dot utah dot edu" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2009-07/txt/msg01205.txt.bz2 Seen on Ubuntu Hardy. The -O2 result seems to be wrong. Also valgrind says this about the -O2 compilation: ==6729== Conditional jump or move depends on uninitialised value(s) ==6729== at 0x84F22CB: solve_graph (tree-ssa-structalias.c:1570) regehr@john-home:~/volatile/tmp174$ current-gcc -O1 small.c -o small regehr@john-home:~/volatile/tmp174$ ./small checksum = 0 regehr@john-home:~/volatile/tmp174$ current-gcc -O2 small.c -o small regehr@john-home:~/volatile/tmp174$ ./small checksum = 1 regehr@john-home:~/volatile/tmp174$ current-gcc -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: ../configure --prefix=/home/regehr/z/tmp/gcc-r149650-install --program-prefix=r149650- --enable-languages=c,c++ Thread model: posix gcc version 4.5.0 20090714 (experimental) (GCC) regehr@john-home:~/volatile/tmp174$ cat small.c #include #include #include uint8_t g_4; int64_t g_10; uint8_t g_56; uint8_t g_64; static uint8_t safe_rshift_func_uint8_t_u_u(uint8_t left, unsigned int right) { return ((((unsigned int)(right)) >= sizeof(uint8_t)*CHAR_BIT) ? ((uint8_t)(left)) : (((uint8_t)(left)) >> ((unsigned int)(right)))); } int32_t func_53 (void); int32_t func_53 (void) { if (safe_rshift_func_uint8_t_u_u (g_56, g_10)) { } else for (g_10 = 0; g_10; g_10 = 1) { } return 1; } int32_t func_36 (void); int32_t func_36 (void) { uint8_t p_40; g_10 = 1; g_10 && func_53 (); p_40 = g_10 || g_4; g_64 = g_10; return 1; } int main (void) { func_36 (); printf ("checksum = %d\n", g_64); return 0; } -- Summary: possible integer miscompilation Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: regehr at cs dot utah dot edu 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=40762