Bug 23427 – ImportC: some bitfield combinations lead to wrong size struct

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
Mac OS X
Creation time
2022-10-20T02:13:24Z
Last change time
2023-04-17T09:42:51Z
Keywords
ImportC, pull, wrong-code
Assigned to
No Owner
Creator
dave287091

Attachments

IDFilenameSummaryContent-TypeSize
1869b.cFailure casestext/plain2760

Comments

Comment #0 by dave287091 — 2022-10-20T02:13:24Z
On macOS, the following C code compiles without failing a static assertion using apple clang. Dmd triggers the static assertion. I haven’t tested other platforms. _Static_assert(sizeof(unsigned) == 4, ""); struct A { unsigned x :8; unsigned y :4; unsigned z :20; }; _Static_assert(sizeof(struct A)==4, ""); struct B { unsigned x :4; unsigned y :2; unsigned z :26; }; _Static_assert(sizeof(struct B)==4, ""); struct C { unsigned x :4; unsigned y :4; unsigned z :24; }; _Static_assert(sizeof(struct C)==4, ""); // This one fails
Comment #1 by dave287091 — 2023-04-13T20:28:55Z
Created attachment 1869 Failure cases I generated all of the possible structs with bitfields totaling to 32 bits and each member having at least 1 bit. All of these assertions pass with clang and fail with dmd on macOS.
Comment #2 by dlang-bot — 2023-04-16T07:56:07Z
@WalterBright created dlang/dmd pull request #15110 "fix Issue 23427 - ImportC: some bitfield combinations lead to wrong s…" fixing this issue: - fix Issue 23427 - ImportC: some bitfield combinations lead to wrong size struct https://github.com/dlang/dmd/pull/15110
Comment #3 by dlang-bot — 2023-04-17T09:42:51Z
dlang/dmd pull request #15110 "fix Issue 23427 - ImportC: some bitfield combinations lead to wrong s…" was merged into master: - 3411937473491cb99afe19c3b1dda3026427875b by Walter Bright: fix Issue 23427 - ImportC: some bitfield combinations lead to wrong size struct https://github.com/dlang/dmd/pull/15110