Bug 23346 – ImportC: pragma pack is not popped

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-09-19T03:56:06Z
Last change time
2022-09-27T12:44:20Z
Keywords
ImportC, pull, wrong-code
Assigned to
No Owner
Creator
dave287091

Comments

Comment #0 by dave287091 — 2022-09-19T03:56:06Z
It seems like #pragma pack(pop) in a C file does not undo a #pragma pack(push). For example (on a target where sizeof(long) == 8): #pragma pack(push, 4) struct Packed { int x; long y; }; #pragma pack(pop) struct NotPacked { int x; // should have 4 bytes of padding long y; }; _Static_assert(sizeof(long)==8, "long is not 8 bytes"); _Static_assert(sizeof(struct Packed)==12, "sizeof(Packed) != 12"); _Static_assert(sizeof(struct NotPacked)==16, "sizeof(NotPacked) != 16”); // This static assertion fails. Compiling with clang passes the static assertions. I noticed this when compiling some code on macOS (which unfortunately uses pragma pack in some system headers).
Comment #1 by dave287091 — 2022-09-26T03:14:37Z
Inserting #pragma pack(show) into the source makes it obvious that pop is not being applied.
Comment #2 by dlang-bot — 2022-09-27T07:31:58Z
@WalterBright created dlang/dmd pull request #14490 "fix Issue 23346 - ImportC: pragma pack is not popped" fixing this issue: - fix Issue 23346 - ImportC: pragma pack is not popped https://github.com/dlang/dmd/pull/14490