-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C front-end: fix processing of alignment and packing attributes #8454
Open
tautschnig
wants to merge
1
commit into
diffblue:develop
Choose a base branch
from
tautschnig:fix-8443-attributes
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
#include <stdint.h> | ||
|
||
struct S1 | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
} __attribute__((packed)); | ||
struct S1 s1; | ||
|
||
struct S1a | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
} __attribute__((packed)) __attribute__((aligned(16))); | ||
struct S1a s1a; | ||
|
||
struct __attribute__((packed)) S2 | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
}; | ||
struct S2 s2; | ||
|
||
struct __attribute__((packed)) __attribute__((aligned(16))) S2a | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
}; | ||
struct S2a s2a; | ||
|
||
// "packed" will be ignored | ||
__attribute__((packed)) struct S3 | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
}; | ||
struct S3 s3; | ||
|
||
// both "packed" and "aligned" | ||
__attribute__((packed)) __attribute__((aligned(16))) struct S3a | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
}; | ||
struct S3a s3a; | ||
|
||
struct S4 | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
} __attribute__((packed)) s4; | ||
|
||
struct S4a | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
} __attribute__((packed)) __attribute__((aligned(16))) s4a; | ||
|
||
struct __attribute__((packed)) S5 | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
} s5; | ||
|
||
struct __attribute__((packed)) __attribute__((aligned(16))) S5a | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
} s5a; | ||
|
||
typedef struct __attribute__((packed)) S6 | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
} s6; | ||
|
||
typedef struct __attribute__((packed)) __attribute__((aligned(16))) S6a | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
} s6a; | ||
|
||
// "packed" will be ignored in the following by both GCC and Clang | ||
struct S7 | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
} s7 __attribute__((packed)); | ||
|
||
// "packed" will be ignored in the following by both GCC and Clang | ||
struct S7a | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
} s7a __attribute__((packed)) __attribute__((aligned(16))); | ||
|
||
typedef struct T1 | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
} __attribute__((packed)) T1_t; | ||
|
||
typedef struct T1a | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
} __attribute__((packed)) __attribute__((aligned(16))) T1a_t; | ||
|
||
typedef struct __attribute__((packed)) T2 | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
} T2_t; | ||
|
||
typedef struct __attribute__((packed)) __attribute__((aligned(16))) T2a | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
} T2a_t; | ||
|
||
struct U | ||
{ | ||
uint8_t c; | ||
int32_t i; | ||
}; | ||
|
||
struct S | ||
{ | ||
uint8_t c; | ||
// attribute ignored by GCC | ||
struct S1 __attribute((packed)) i1; | ||
struct U __attribute((packed)) i2; | ||
uint8_t c2; | ||
// alignment has to be a power of 2 | ||
// struct S2 __attribute((aligned(5))) i2_5; | ||
struct S2a __attribute((aligned(8))) i3; | ||
uint8_t c3; | ||
struct S3a __attribute((aligned(8))) i4; | ||
uint8_t c4; | ||
T1a_t __attribute((aligned(8))) i5; | ||
T1_t __attribute((aligned(8))) i6; | ||
}; | ||
|
||
int32_t main() | ||
{ | ||
_Static_assert(sizeof(struct S1) == 5, ""); | ||
_Static_assert(sizeof(s1) == 5, ""); | ||
_Static_assert(sizeof(struct S1a) == 16, ""); | ||
_Static_assert(sizeof(s1a) == 16, ""); | ||
|
||
_Static_assert(sizeof(struct S2) == 5, ""); | ||
_Static_assert(sizeof(s2) == 5, ""); | ||
_Static_assert(sizeof(struct S2a) == 16, ""); | ||
_Static_assert(sizeof(s2a) == 16, ""); | ||
|
||
_Static_assert(sizeof(struct S3) == 8, ""); | ||
_Static_assert(sizeof(s3) == 8, ""); | ||
_Static_assert(sizeof(struct S3a) == 8, ""); | ||
_Static_assert(sizeof(s3a) == 8, ""); | ||
|
||
_Static_assert(sizeof(struct S4) == 5, ""); | ||
_Static_assert(sizeof(s4) == 5, ""); | ||
_Static_assert(sizeof(struct S4a) == 16, ""); | ||
_Static_assert(sizeof(s4a) == 16, ""); | ||
|
||
_Static_assert(sizeof(struct S5) == 5, ""); | ||
_Static_assert(sizeof(s5) == 5, ""); | ||
_Static_assert(sizeof(struct S5a) == 16, ""); | ||
_Static_assert(sizeof(s5a) == 16, ""); | ||
|
||
_Static_assert(sizeof(struct S6) == 5, ""); | ||
_Static_assert(sizeof(s6) == 5, ""); | ||
_Static_assert(sizeof(struct S6a) == 16, ""); | ||
_Static_assert(sizeof(s6a) == 16, ""); | ||
|
||
_Static_assert(sizeof(struct S7) == 8, ""); | ||
_Static_assert(sizeof(s7) == 8, ""); | ||
_Static_assert(sizeof(struct S7a) == 8, ""); | ||
_Static_assert(sizeof(s7a) == 8, ""); | ||
|
||
_Static_assert(sizeof(struct T1) == 5, ""); | ||
_Static_assert(sizeof(T1_t) == 5, ""); | ||
_Static_assert(sizeof(struct T1a) == 16, ""); | ||
_Static_assert(sizeof(T1a_t) == 16, ""); | ||
|
||
_Static_assert(sizeof(struct T2) == 5, ""); | ||
_Static_assert(sizeof(T2_t) == 5, ""); | ||
_Static_assert(sizeof(struct T2a) == 16, ""); | ||
_Static_assert(sizeof(T2a_t) == 16, ""); | ||
|
||
_Static_assert(sizeof(struct S) == 96, ""); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE gcc-only | ||
main.c | ||
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
^CONVERSION ERROR$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that a requirement in the standard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C11 6.2.8 "Alignment of objects" includes the following sentence: "Every valid alignment value shall be a nonnegative integral power of two."