This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/40762] New: possible integer miscompilation


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 <stdint.h>
#include <limits.h>
#include <stdio.h>

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]