A bitfield, less than 64 bits, does not zero out when a 1 is shifted left
passed the left most bit. The following test will return 65 instead of 57.

command line:
gcc -Wall -O2 gcc-bitfield-bug.c

gcc-bitfield-bug.c:

#include <stdio.h>

//64 bit bitfield
struct aa {
    unsigned long long f:( 56 )  __attribute__((packed));
} s;

int main ()
{
    s.f = 1;
    int c;
    for(c=1; c<=64; c++) {
        if(s.f==0) break;
        s.f <<= 1;
    }
    printf("%d\n", c);
    return 0;
}


-- 
           Summary: bitfield shift fails with optimizer (-O2)
           Product: gcc
           Version: 4.2.4
            Status: UNCONFIRMED
          Severity: blocker
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ata at earthdetails dot com
  GCC host triplet: i386 (pentium duocore)
GCC target triplet: i386 (pentium duocore)


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37918

Reply via email to