[llvm-bugs] [Bug 32708] New: The shift didn't carry out the value in bit-field structure

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Apr 19 00:00:29 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=32708

            Bug ID: 32708
           Summary: The shift didn't carry out the value in bit-field
                    structure
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: shiva0217 at gmail.com
                CC: llvm-bugs at lists.llvm.org

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;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170419/dec07666/attachment-0001.html>


More information about the llvm-bugs mailing list