-
Notifications
You must be signed in to change notification settings - Fork 273
make pointer_offset_exprt unsigned #6893
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.
I'm unconvinced the required change is as small as the current PR suggests: there are several uses of bv_utils.sign_extension
in bv_pointers.cpp
, and I believe these need to be changed.
c6ae1ab
to
cdcba8f
Compare
Codecov ReportBase: 78.48% // Head: 78.48% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## develop #6893 +/- ##
===========================================
- Coverage 78.48% 78.48% -0.01%
===========================================
Files 1663 1663
Lines 191189 191232 +43
===========================================
+ Hits 150055 150082 +27
- Misses 41134 41150 +16
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Slightly amending my concern as discussed out of band: we likely make a mess at the moment when converting the result of pointer (offset) arithmetic back to the bit-limited offset representation where we may or may not end up producing a negative number in case of overflow/underflow. This needs looking into, or perhaps we should just invest our energy in the alternative pointer encodings. |
I believe the only missing piece for this one is adjusting |
cdcba8f
to
d107e31
Compare
We now have a bunch of failing regression tests with |
ebb0827
to
2a46b9f
Compare
2a46b9f
to
1183c4a
Compare
6aa4277
to
b200467
Compare
b200467
to
268b6c3
Compare
268b6c3
to
8ef892c
Compare
8ef892c
to
1cfb9cf
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.
Adding a temporary blocker: I am now expecting all tests to pass, but @remi-delmas-3000 is taking a look at all pointer arithmetic done contracts code to make sure no further updates are required.
I wrote a test to check that I can perform inclusion checks using pointers that are one past the end of the object, it seems to work except for one thing I don’t understand:
the third assertion is falsified with
In the trace size is taken to be max_malloc_size-1 so that the offset of The counter example goes away if we restrict the allocation size to be strictly less than I wasn't expecting unsigned offsets to use the full width, rather max_malloc_size is still defined as 2^(offset_bits-1) so technically we could still add (max_malloc_size-1) to max_malloc_size before having to overflow into object bits in the pointer representation. |
There already is an assertion in place to guard against undefined behaviour. We shouldn't have to match on particular outcomes of undefined behaviour that occurs after that assertion.
We must not assume that byte-operator offsets and arrays indices use the same type (without at least checking that they do). Always use types available from the context, and type cast as needed.
Make sure that replace_expr cannot introduce type-inconsistent expressions. This wouldn't be a fault of replace_expr, but rather requires fixing the caller. Add preconditions to check this.
723ea09
to
32fd591
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.
I have now included the test posted by @remi-delmas-3000 together with further fixes (ensuring that we always interpret the offset as unsigned).
This commit changes the type of __CPROVER_POINTER_OFFSET from ssize_t to size_t. To match, relational operators on pointers are now unsigned, to enable p+PTRDIFF_MAX+1 > p. The rationale is subtle. The ISO C 11 standard 6.5.8 par 5 suggests that a pair of pointers can be compared if either the pointers point into the object, or one beyond the end of the sequence. The behavior in the case of a pointer that points before the sequence is undefined. There is a similar narrative for pointer arithmetic. A pointer with an offset that has a set most significant bit should thus compare "less than" a pointer with an offset that has a zero MSB. This suggests an unsigned encoding.
32fd591
to
7cb83c1
Compare
This commit changes the type of
__CPROVER_POINTER_OFFSET
fromssize_t
tosize_t
. To match, relational operators on pointers are now unsigned, toenable
p+PTRDIFF_MAX+1 > p
.The rationale is subtle. The ISO C 11 standard 6.5.8 par 5 suggests that a
pair of pointers can be compared if either the pointers point into the
object, or one beyond the end of the sequence. The behavior in the case of
a pointer that points before the sequence is undefined. There is a similar
narrative for pointer arithmetic. A pointer with an offset that has a set
most significant bit should thus compare "less than" a pointer with an
offset that has a zero MSB. This suggests an unsigned encoding.