Bug 23293 – ImportC: _Bool bit fields layout does not match gcc

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2022-08-14T18:44:05Z
Last change time
2022-10-05T07:21:35Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
kinke

Comments

Comment #0 by kinke — 2022-08-14T18:44:05Z
This C code fails with DMD v2.100.1 on Linux x64: ``` struct S { unsigned char a:7; // byte offset 0, bit offset 0 _Bool b:1; // byte offset 0, bit offset 7 _Bool c:1; // byte offset 1, bit offset 0 unsigned d:22; // byte offset 1, bit offset 1 _Bool e:1; // byte offset 4, bit offset 0 (wrong) // should probably be: byte offset 3, bit offset 7 // or: byte offset 1, bit offset 23 }; _Static_assert(sizeof(struct S) == 4, "size != 4"); // 8 with DMD ``` The size is 4 with both latest clang and gcc on Linux: https://cpp.godbolt.org/z/h4z938e5z I haven't checked on Windows.
Comment #1 by bugzilla — 2022-09-30T08:39:29Z
Simpler test case: struct S { unsigned d:31; _Bool e:1; }; _Static_assert(sizeof(struct S) == 4, "size != 4"); // 8 with DMD
Comment #2 by dlang-bot — 2022-10-05T03:45:07Z
@WalterBright updated dlang/dmd pull request #14508 "fix Issue 23293 - ImportC: _Bool bit fields layout does not match gcc" fixing this issue: - fix Issue 23293 - ImportC: _Bool bit fields layout does not match gcc https://github.com/dlang/dmd/pull/14508
Comment #3 by dlang-bot — 2022-10-05T07:21:35Z
dlang/dmd pull request #14508 "fix Issue 23293 - ImportC: _Bool bit fields layout does not match gcc" was merged into master: - c8b86e758372c55f0267be8096cd9d4bf04666df by Walter Bright: fix Issue 23293 - ImportC: _Bool bit fields layout does not match gcc https://github.com/dlang/dmd/pull/14508