Issue 24733 - ImportC: `#pragma pack(pop)` restores wrong alignment
Summary: ImportC: `#pragma pack(pop)` restores wrong alignment
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords: ImportC, pull
Depends on:
Blocks:
 
Reported: 2024-08-30 15:44 UTC by Tim
Modified: 2024-08-31 19:32 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Tim 2024-08-30 15:44:36 UTC
```
struct S1 {unsigned char c;int i;};
#pragma pack(push, 2)
struct S2 {unsigned char c;int i;};
#pragma pack(push, 1)
struct S3 {unsigned char c;int i;};
#pragma pack(pop)
struct S4 {unsigned char c;int i;};
#pragma pack(pop)
struct S5 {unsigned char c;int i;};

_Static_assert(_Alignof(struct S1) == 4, "alignof S1");
_Static_assert(_Alignof(struct S2) == 2, "alignof S2");
_Static_assert(_Alignof(struct S3) == 1, "alignof S3");
_Static_assert(_Alignof(struct S4) == 2, "alignof S4"); // fails
_Static_assert(_Alignof(struct S5) == 4, "alignof S5");

_Static_assert(sizeof(struct S1) == 8, "sizeof S1");
_Static_assert(sizeof(struct S2) == 6, "sizeof S2");
_Static_assert(sizeof(struct S3) == 5, "sizeof S3");
_Static_assert(sizeof(struct S4) == 6, "sizeof S4"); // fails
_Static_assert(sizeof(struct S5) == 8, "sizeof S5");
```
Comment 1 Dlang Bot 2024-08-30 15:47:24 UTC
@tim-dlang created dlang/dmd pull request #16821 "Fix bugzilla 24733 - ImportC: `#pragma pack(pop)` restores wrong alignment" fixing this issue:

- Fix bugzilla 24733 - ImportC: `#pragma pack(pop)` restores wrong alignment

https://github.com/dlang/dmd/pull/16821
Comment 2 Dlang Bot 2024-08-31 19:32:03 UTC
dlang/dmd pull request #16821 "Fix bugzilla 24733 - ImportC: `#pragma pack(pop)` restores wrong alignment" was merged into master:

- 626c0a5ab70f4f79f970157656fa00fc1fd3e722 by Tim Schendekehl:
  Fix bugzilla 24733 - ImportC: `#pragma pack(pop)` restores wrong alignment

https://github.com/dlang/dmd/pull/16821