public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hjl.tools at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/107403] New: uint64_t bitfield operation is mishandled
Date: Tue, 25 Oct 2022 23:55:33 +0000	[thread overview]
Message-ID: <bug-107403-4@http.gcc.gnu.org/bugzilla/> (raw)

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	other threads:[~2022-10-25 23:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25 23:55 hjl.tools at gmail dot com [this message]
2022-10-26  0:00 ` [Bug target/107403] " pinskia at gcc dot gnu.org
2022-10-26  0:00 ` pinskia at gcc dot gnu.org
2022-10-26  0:05 ` pinskia at gcc dot gnu.org
2022-10-26  0:06 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-107403-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).