Bug 24592 – ImportC: Bitfield layout wrong for int64 on 32-bit Linux
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2024-06-09T14:21:13Z
Last change time
2024-06-17T00:31:09Z
Keywords
pull
Assigned to
No Owner
Creator
Tim
Comments
Comment #0 by tim.dlang — 2024-06-09T14:21:13Z
The followng struct from /usr/include/linux/perf_event.h has the wrong size with ImportC:
```
struct perf_branch_entry {
__u64 from;
__u64 to;
__u64 mispred:1, /* target mispredicted */
predicted:1,/* target predicted */
in_tx:1, /* in transaction */
abort:1, /* transaction abort */
cycles:16, /* cycle count to last branch */
type:4, /* branch type */
spec:2, /* branch speculation info */
new_type:4, /* additional branch type */
priv:3, /* privilege level */
reserved:31;
};
```
With ImportC and dmd -m32 on Linux this has size 28, but with gcc -m32 it has size 24.
Found by comparing type sizes in druntime with type sizes found with ImportC: https://github.com/dlang/dmd/pull/16571
Comment #1 by dlang-bot — 2024-06-16T17:00:42Z
@tim-dlang created dlang/dmd pull request #16590 "Fix bugzilla 24592 - ImportC: Bitfield layout wrong for int64 on 32-b…" fixing this issue:
- Fix bugzilla 24592 - ImportC: Bitfield layout wrong for int64 on 32-bit Linux
Type ulong is 64-bit on 32-bit Linux, but has 32-bit alignment.
This affects the layout of bitfields.
Also add a new test for ImportC bitfields, which compares size,
alignment and layout with the host C++ compiler. The existing
tests compared with fixed values instead.
https://github.com/dlang/dmd/pull/16590
Comment #2 by dlang-bot — 2024-06-17T00:31:09Z
dlang/dmd pull request #16590 "Fix bugzilla 24592 - ImportC: Bitfield layout wrong for int64 on 32-b…" was merged into master:
- e427ca656d801bcc438afce7fd6fba94d0e860c5 by Tim Schendekehl:
Fix bugzilla 24592 - ImportC: Bitfield layout wrong for int64 on 32-bit Linux
Type ulong is 64-bit on 32-bit Linux, but has 32-bit alignment.
This affects the layout of bitfields.
Also add a new test for ImportC bitfields, which compares size,
alignment and layout with the host C++ compiler. The existing
tests compared with fixed values instead.
https://github.com/dlang/dmd/pull/16590