Skip to content

Commit

Permalink
Fix bugzilla 24733 - ImportC: #pragma pack(pop) restores wrong alig…
Browse files Browse the repository at this point in the history
…nment (#16821)
  • Loading branch information
tim-dlang authored Aug 31, 2024
1 parent 452ebe2 commit 6884b43
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dmd/cparse.d
Original file line number Diff line number Diff line change
Expand Up @@ -5813,7 +5813,7 @@ final class CParser(AST) : Parser!AST
if (len == 1) // stack is now empty
packalign.setDefault();
else
packalign = (*this.packs)[len - 1];
packalign = (*this.packs)[len - 2];
return closingParen();
}
while (n.value == TOK.comma) // #pragma pack ( pop ,
Expand Down
21 changes: 21 additions & 0 deletions compiler/test/compilable/test24733.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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");
_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");
_Static_assert(sizeof(struct S5) == 8, "sizeof S5");

0 comments on commit 6884b43

Please sign in to comment.