https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107403

            Bug ID: 107403
           Summary: uint64_t bitfield operation is mishandled
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hjl.tools at gmail dot com
  Target Milestone: ---
            Target: x84

[hjl@gnu-cfl-1 tmp]$ cat foo.c
#include <stdint.h>
#include <stdio.h>

#define VAL (1ULL << 48)

struct foo
{
  uint64_t x : 8;
  uint64_t y : 56;
};

__attribute__ ((noinline))
uint64_t
func (struct foo i)
{
  return i.y << 8ULL;
}

int
main ()
{
  struct foo i;
  i.x = 0;
  i.y = VAL;
  uint64_t x = func (i);
  printf ("0x%llx\n", x);
  printf ("0x%llx\n", VAL);
  if (x != (VAL << 8ULL))
    __builtin_abort ();
}
[hjl@gnu-cfl-1 tmp]$ gcc foo.c
[hjl@gnu-cfl-1 tmp]$ ./a.out 
0x0
0x1000000000000
Aborted (core dumped)
[hjl@gnu-cfl-1 tmp]$

Reply via email to