llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

The shift didn't carry out the value in bit-field structure

Open ShivaChen opened this issue 9 years ago • 1 comments

Bugzilla Link 32708
Resolution DUPLICATE
Resolved on Apr 19, 2017 12:39
Version trunk
OS Linux
CC @efriedma-quic,@hfinkel

Extended Description

According to C99 6.7.2.1

9 A bit-field is interpreted as a signed or unsigned integer type consisting of the specified number of bits. So the bit exceed the number of bits after shift should carry out.

In the following case, x.b:40 initial as 0x0100 should carry out to 0 after (x.b<<32)

struct foo { unsigned long long b:40; } x;

extern void abort (void);

void test1(unsigned long long res) { /* The shift is carried out in 40 bit precision. */ if (x.b<<32 != res) abort (); }

int main() { x.b = 0x0100; test1(0); return 0; }

ShivaChen avatar Apr 19 '17 07:04 ShivaChen

*** This bug has been marked as a duplicate of bug llvm/llvm-project#17673 ***

efriedma-quic avatar Apr 19 '17 19:04 efriedma-quic