-
Notifications
You must be signed in to change notification settings - Fork 99
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
Don't use the broken overflow builtins for pointers #791
Conversation
@@ -851,13 +852,10 @@ impl Expr { | |||
// Floating Point Equalities | |||
IeeeFloatEqual | IeeeFloatNotequal => lhs.typ == rhs.typ && lhs.typ.is_floating_point(), | |||
// Overflow flags | |||
OverflowMinus => { | |||
(lhs.typ == rhs.typ && (lhs.typ.is_pointer() || lhs.typ.is_numeric())) |
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.
Good to restrict this case to integers because I do not think we were handling floating point numbers anyway.
I don't have a lot of context here, but I thought that was the goal of these checks. They were complementary to CBMC pointer checks. These were just making sure the arithmetic operations would not overflow. One could argue that they are redundant but I don't know if broken is how I would describe them. |
Can you please add a test that would trigger the overflow to ensure the verification will still fail due to other checks? |
af8d832
to
e380232
Compare
Done |
The issue is that the semantics of the arithmetic operation being done, and the semantics of the check, don't line up. The arithmetic operation is doing pointer arithmetic, while the overflow check is doing integer arithmetic. So its possible for the actual addition to overflow, but the overflow check to report no overflow. |
Can we account for the type size? |
I believe this change is currently blocked waiting for a CBMC fix to be released. @danielsn Please let us know once this is ready for review again. Cheers! |
Description of changes:
Currently, we emit
__builtin_overflow_p
operations for pointer arithmetic. This is basically broken, since CBMC converts to integers and does integer arithmetic under the hood, which is not what we want.Resolved issues:
Initial step towards addressing #786
Call-outs:
This relies on
--pointer-overflow-check
being used on CBMC for soundness. We currently do so, but it would be better to have a__pointer_overflow
builtin we could use when we need this behaviour. The overflow intrinsics have surprising behaviour on pointer arithmatic diffblue/cbmc#6627Also fixed some confusing missing brackets in the typechecking code for binops.
Testing:
How is this change tested? Existing regression tests.
Is this a refactor change? No
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.