Bug 24594 – ImportC: Packed struct has wrong layout

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2024-06-09T14:25:17Z
Last change time
2024-06-22T12:48:14Z
Keywords
pull
Assigned to
No Owner
Creator
Tim

Comments

Comment #0 by tim.dlang — 2024-06-09T14:25:17Z
``` #include <stdio.h> #include <stdint.h> struct epoll_event { uint32_t events; uint64_t data; } __attribute__((packed)); int main() { printf("size: %zd\n", sizeof(struct epoll_event)); printf("data offset: %zd\n", &((struct epoll_event*)0)->data); } ``` Output with gcc: size: 12 data offset: 4 Output with dmd: size: 16 data offset: 8 The type epoll_event is originally from Linux header /usr/include/sys/epoll.h, but modified for this test. The problem was 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-22T11:48:56Z
@tim-dlang created dlang/dmd pull request #16611 "Fix bugzilla 24594 - ImportC: Packed struct has wrong layout" fixing this issue: - Fix bugzilla 24594 - ImportC: Packed struct has wrong layout Packed structs were already implemented with the Microsoft syntax (e.g. `#pragma pack(push, 1)`), but the GCC syntax was ignored. https://github.com/dlang/dmd/pull/16611
Comment #2 by dlang-bot — 2024-06-22T12:48:14Z
dlang/dmd pull request #16611 "Fix bugzilla 24594 - ImportC: Packed struct has wrong layout" was merged into master: - d02e12b8ddcf66d435265d443af34f8d3f25faaf by Tim Schendekehl: Fix bugzilla 24594 - ImportC: Packed struct has wrong layout Packed structs were already implemented with the Microsoft syntax (e.g. `#pragma pack(push, 1)`), but the GCC syntax was ignored. https://github.com/dlang/dmd/pull/16611