It looks wrong at -Os.  The compiler is valgrind-clean at that level.

reg...@john-home:~/volatile/tmp200$ current-gcc -O small.c -o small
reg...@john-home:~/volatile/tmp200$ ./small
checksum = -13

reg...@john-home:~/volatile/tmp200$ current-gcc -Os small.c -o small
reg...@john-home:~/volatile/tmp200$ ./small
checksum = 65523

reg...@john-home:~/volatile/tmp200$ current-gcc -v

Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../configure --prefix=/home/regehr/z/tmp/gcc-r152261-install
--program-prefix=r152261- --enable-languages=c,c++
Thread model: posix
gcc version 4.5.0 20090929 (experimental) (GCC) 

reg...@john-home:~/volatile/tmp200$ cat small.c

#include <stdint.h>
#include <stdio.h>

static uint16_t add (uint16_t ui1, uint16_t ui2)
{
  return ui1 + ui2;
}

uint32_t g_108;
uint8_t f3;
uint8_t f0;

void func_1 (void);
void func_1 (void)
{
  for (f3 = 0; f3 <= 0; f3 = 1) {
    for (g_108 = -13; g_108 == 0; g_108 = add (g_108, 0)) {
      f0 = 1;
    }
  }
}

int
main (void)
{
  func_1 ();
  printf ("checksum = %d\n", g_108);
  return 0;
}


-- 
           Summary: apparent integer wrong code bug
           Product: gcc
           Version: unknown
            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=41497

Reply via email to