public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/55658] New: bitfields and __attribute__((packed)) generate horrible code on x86_64
@ 2012-12-12  5:54 tudorb at fb dot com
  2012-12-12  6:02 ` [Bug middle-end/55658] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: tudorb at fb dot com @ 2012-12-12  5:54 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 55658
           Summary: bitfields and __attribute__((packed)) generate
                    horrible code on x86_64
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tudorb@fb.com


Created attachment 28932
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28932
Simple source code to exhibit the problem; disassembly (as produced by objdump
-d)

I have a structure defined as:

struct D {
  uint64_t id_ : 63;
  bool x_ : 1;
} __attribute__((packed));

uint64_t D_id(const struct D* p) { return p->id_; }

The generated code for D_id (using gcc 4.7.1 -O2 on Linux x86_64) builds the
return value byte by byte and masks out the most significant bit from the last
byte.

Removing __attribute__((packed)) and/or changing the structure so it is no
longer a bitfield generates sane code.

This happens in both C and C++ (unsurprisingly).


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-02-25 22:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-12  5:54 [Bug c/55658] New: bitfields and __attribute__((packed)) generate horrible code on x86_64 tudorb at fb dot com
2012-12-12  6:02 ` [Bug middle-end/55658] " pinskia at gcc dot gnu.org
2012-12-12  6:11 ` pinskia at gcc dot gnu.org
2012-12-12 10:00 ` rguenth at gcc dot gnu.org
2023-02-25  6:40 ` pinskia at gcc dot gnu.org
2023-02-25  6:44 ` pinskia at gcc dot gnu.org
2023-02-25 20:53 ` pinskia at gcc dot gnu.org
2023-02-25 22:06 ` pinskia at gcc dot gnu.org

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).