gcc version 4.2.0 20060121

With optimzation the following code skips the last loop iteration:

#include <stdio.h>

int main(void)
{
        int bits = 25;
        while (bits) {
                printf("bits=%d\n",bits);
                if (bits >= 8) {
                        bits -= 8;
                } else {
                        bits = 0;
                }

        }
        return 0;
}

[EMAIL PROTECTED]:~/pg/test$ ~/gcc/42/bin/gcc  ip2.c 
[EMAIL PROTECTED]:~/pg/test$ ./a.out 
bits=25
bits=17
bits=9
bits=1
[EMAIL PROTECTED]:~/pg/test$ ~/gcc/42/bin/gcc -O ip2.c 
[EMAIL PROTECTED]:~/pg/test$ ./a.out 
bits=25
bits=17
bits=9
[EMAIL PROTECTED]:~/pg/test$


-- 
           Summary: with optimization integer math fails
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jurka at ejurka 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=25985

Reply via email to