-
Notifications
You must be signed in to change notification settings - Fork 271
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
Assignments to bit-fields yield results of bit-field type #8082
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,36 @@ | ||
#include <assert.h> | ||
#include <limits.h> | ||
|
||
struct S0 | ||
{ | ||
unsigned f2 : CHAR_BIT + 1; | ||
int x; | ||
}; | ||
|
||
#ifdef _MSC_VER | ||
# define _Static_assert static_assert | ||
#endif | ||
|
||
int main() | ||
{ | ||
struct S0 g = {0}; | ||
// All compilers in compiler explorer appear to agree that comma and | ||
// assignment expressions over bit-fields permit the use of sizeof. With GCC, | ||
// the result is the declared width (rounded to bytes), all others use the | ||
// size of the underlying type. | ||
// https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2958.htm | ||
// for a discussion that this isn't actually specified (while being a | ||
// sizeof/typeof peculiarity) | ||
#if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__) | ||
# define WIDTH 2 | ||
#else | ||
# define WIDTH sizeof(unsigned) | ||
#endif | ||
_Static_assert(sizeof(++g.f2) == WIDTH, ""); | ||
_Static_assert(sizeof(0, g.f2) == WIDTH, ""); | ||
_Static_assert(sizeof(g.f2 = g.f2) == WIDTH, ""); | ||
if(g.f2 <= -1) | ||
assert(0); | ||
if((g.f2 = g.f2) <= -1) | ||
assert(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 | ||
main.c | ||
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
^warning: ignoring |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected] | |
#include "goto_program2code.h" | ||
|
||
#include <util/arith_tools.h> | ||
#include <util/bitvector_expr.h> | ||
#include <util/c_types.h> | ||
#include <util/expr_util.h> | ||
#include <util/ieee_float.h> | ||
|
@@ -1435,6 +1436,19 @@ void goto_program2codet::cleanup_code( | |
|
||
if(code.op0().type().id()==ID_array) | ||
cleanup_expr(to_array_type(code.op0().type()).size(), true); | ||
else if(code.op0().type().id() == ID_c_bit_field) | ||
{ | ||
c_bit_field_typet original_type = to_c_bit_field_type(code.op0().type()); | ||
bitvector_typet bv_type = | ||
to_bitvector_type(original_type.underlying_type()); | ||
code.op0().type() = bv_type; | ||
if(code.operands().size() == 2) | ||
{ | ||
exprt bit_mask = | ||
from_integer(power(2, original_type.get_width()) - 1, bv_type); | ||
code.op1() = bitand_exprt{code.op1(), bit_mask}; | ||
} | ||
} | ||
|
||
add_local_types(code.op0().type()); | ||
|
||
|
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.
(Still GCC's interpretation makes considerably more sense than the others'.)