-
Notifications
You must be signed in to change notification settings - Fork 274
Byte-update lowering: handle sub-byte sized bit fields #5390
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <assert.h> | ||
#include <string.h> | ||
|
||
struct blob | ||
{ | ||
unsigned dummy; | ||
unsigned bit : 1; | ||
}; | ||
|
||
int main() | ||
{ | ||
struct blob b; | ||
struct blob b1 = b; | ||
|
||
// Perform byte-wise updates of the struct, up to its full size. Constant | ||
// propagation made impossible, and thus the byte updates need to be handled | ||
// by the back-end. | ||
if(b.dummy <= sizeof(struct blob)) | ||
memset(&b, 0, b.dummy); | ||
|
||
// If we updated the complete struct, then the single-bit bit-field needs to | ||
// have been set to zero as well. This makes sure that the encoding of byte | ||
// update properly handles fields that are smaller than bytes. | ||
assert(b1.dummy != sizeof(struct blob) || b.bit == 0); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests: can we test behaviour in the other endianness somehow? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think endianness actually matters in this test? |
||
main.c | ||
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
^warning: ignoring |
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.
Brutal! If you are need to change things in this PR, please could you add a comment or two here to explain what you are testing because I fear that people without your knowledge of C struct packing rules and how they relate to bit-fields might miss some of the subtlety here.
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.
Done.