Bug 23936 – ImportC: pragma pack is not working for structs

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-05-25T09:33:36Z
Last change time
2023-05-30T06:40:55Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
a11e99z

Attachments

IDFilenameSummaryContent-TypeSize
1877libuv_pragma_pack.zipprecompiled libuv uv9.i & manual created impc.iapplication/x-zip-compressed146028

Comments

Comment #0 by black80 — 2023-05-25T09:33:36Z
Created attachment 1877 precompiled libuv uv9.i & manual created impc.i issue for latest beta DMD/LDC compilers. they proceeding #pragma pack()/__pragma(pack()) with unknown issue: OK: u can change alignment for impc.SomeType. both compilers works fine and prints 16 or anything. FAILED: u can not change alignment for (as example) uv9.M128A, uv9.CONTEXT. its always 8. IMO some problems with many push/pop in module. push should work for empty/filled stack and no deep constraint for it. PS I added precompiled and manually changed uv9.i to attachment cuz subj is working for manually created impc.i but not working for libuv' uv9.i.
Comment #1 by bugzilla — 2023-05-29T07:33:03Z
The problem can be duplicated with: test.d: import impc; pragma(msg, "M128A.align ", M128A.alignof ); pragma(msg, "_CONTEXT.align ", _CONTEXT.alignof ); pragma(msg, "SomeType.align ", SomeType.alignof ); impc.i: __pragma(pack(push, 16)) typedef struct /*garbage*/ { long long val; } SomeType, *PSomeType; __pragma(pack(pop)) #pragma pack(push,16) __pragma(pack(push,16)) typedef struct /*__declspec(align(16))*/ _M128A { long long Low; long long High; } M128A, *PM128A; __pragma(pack(pop)) #pragma pack(pop) #pragma pack(push,16) __pragma(pack(push,16)) typedef struct _CONTEXT { int LastExceptionFromRip; } CONTEXT, *PCONTEXT; //__attribute__((aligned( 16))), *PCONTEXT; __pragma(pack(pop)) #pragma pack(pop) compiling: M128A.align 8LU _CONTEXT.align 4LU SomeType.align 16LU Something seems wrong with __pragma.
Comment #2 by bugzilla — 2023-05-29T07:41:27Z
Further investigation shows that it works if the struct is anonymous, does not otherwise.
Comment #3 by dlang-bot — 2023-05-30T00:46:13Z
@WalterBright created dlang/dmd pull request #15278 "fix Issue 23936 - ImportC: pragma pack is not working for structs" fixing this issue: - fix Issue 23936 - ImportC: pragma pack is not working for structs https://github.com/dlang/dmd/pull/15278
Comment #4 by dlang-bot — 2023-05-30T06:40:55Z
dlang/dmd pull request #15278 "fix Issue 23936 - ImportC: pragma pack is not working for structs" was merged into master: - e696adf37d83ee456680035bc517fb3b8edce293 by Walter Bright: fix Issue 23936 - ImportC: pragma pack is not working for structs https://github.com/dlang/dmd/pull/15278