-
Notifications
You must be signed in to change notification settings - Fork 273
Evaluating sizeof over __CPROVER_bool requires special cases #3183
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
Conversation
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.
This PR failed Diffblue compatibility checks (cbmc commit: 25fbdf0).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/87986592
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.
Common spurious failures:
- the cbmc commit has disappeared in the mean time (e.g. in a force-push)
- the author is not in the list of contributors (e.g. first-time contributors).
The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.
25fbdf0
to
b7703ab
Compare
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.
This PR failed Diffblue compatibility checks (cbmc commit: b7703ab).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/88031357
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.
Common spurious failures:
- the cbmc commit has disappeared in the mean time (e.g. in a force-push)
- the author is not in the list of contributors (e.g. first-time contributors).
The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.
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.
In some places you align to config.ansi_c.char_width
and in others to 8; check if we're using the right one in the right place? Otherwise just one nitpick to attend.
src/util/pointer_offset_size.cpp
Outdated
++bit_field_bits; | ||
const std::size_t bytes = bit_field_bits / 8; | ||
bit_field_bits %= 8; | ||
result = plus_exprt(result, from_integer(bytes, result.type())); |
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.
Perhaps check for bytes == 0 to avoid creating a needless stack of +0s that will needlessly obscure what we're doing if not simplified away yet?
b7703ab
to
8f299c7
Compare
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.
Passed Diffblue compatibility checks (cbmc commit: 8f299c7).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/88745816
@@ -979,7 +979,7 @@ void c_typecheck_baset::typecheck_expr_sizeof(exprt &expr) | |||
|
|||
exprt new_expr; | |||
|
|||
if(type.id()==ID_c_bit_field) | |||
if(type.id() == ID_c_bit_field || type.id() == ID_bool) | |||
{ | |||
err_location(expr); | |||
error() << "sizeof cannot be applied to bit fields" << eom; |
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.
The error message may be a bit confusing -- I'd give this a separate case.
src/ansi-c/c_typecheck_expr.cpp
Outdated
@@ -1733,7 +1733,7 @@ void c_typecheck_baset::typecheck_expr_address_of(exprt &expr) | |||
|
|||
exprt &op=expr.op0(); | |||
|
|||
if(op.type().id()==ID_c_bit_field) | |||
if(op.type().id() == ID_c_bit_field || op.type().id() == ID_bool) | |||
{ | |||
err_location(expr); | |||
error() << "cannot take address of a bit field" << eom; |
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.
Same here.
8f299c7
to
7164e6e
Compare
__CPROVER_bool is just a single bit, and not part of any language standard describing the semantics of sizeof. We can declare arrays of __CPROVER_bool, which will thus have elements that are not aligned on byte boundaries. Using sizeof with such an array thus requires specific handling.
7164e6e
to
3124621
Compare
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 3124621).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/89538458
__CPROVER_bool is just a single bit, and not part of any language standard
describing the semantics of sizeof. We can declare arrays of __CPROVER_bool,
which will thus have elements that are not aligned on byte boundaries. Using
sizeof with such an array thus requires specific handling.