-
Notifications
You must be signed in to change notification settings - Fork 274
VSD pointer arithmetic, differencing, and comparisons #5678
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
VSD pointer arithmetic, differencing, and comparisons #5678
Conversation
314828d
to
fdea979
Compare
Codecov Report
@@ Coverage Diff @@
## develop #5678 +/- ##
=========================================
Coverage 76.16% 76.17%
=========================================
Files 1484 1484
Lines 162164 162317 +153
=========================================
+ Hits 123516 123646 +130
- Misses 38648 38671 +23
Continue to review full report at Codecov.
|
0fac00e
to
c844d94
Compare
Build Xen with CPROVER tools / CompileXen (pull_request) is failing for unrelated reasons.
|
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 like what this is doing, there are a few places where I feel how it is doing it could be better. I suspect "better" here means deeper and more intrusive changes to the write_stack
parts and constant_pointer_abstract_objectt
which are only obviously "better" when taking into account a load of other things so why don't we have a chat and see what can be done?
regression/goto-analyzer/pointer-difference-after-decrement/test.desc
Outdated
Show resolved
Hide resolved
offset = (q - p); | ||
assert(offset == 0); | ||
assert(q == p); | ||
} |
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.
Nice test!
@@ -97,6 +97,15 @@ class pointer_abstract_objectt : public abstract_objectt | |||
protected: | |||
CLONE | |||
|
|||
virtual bool same_target(abstract_object_pointert other) const |
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 am not entirely opposed to adding to the interface for pointers if it is necessary. However there is a general move towards making the interface of abstract_objectt
and children more uniform so I wonder if there is another way.
d93594a
to
5fedaf1
Compare
5fedaf1
to
e092e9f
Compare
If a pointer addition simplifies to p+a, if we continue to simplify we risk incorrectly eliminating zeros from the expression, erroneously going to TOP when we would otherwise have a correct pointer to the base object.
Detect case by checking expr has ID_minus and the operands are both pointers
It implements some of what should be two_value_pointer_abstract_object, so moved that out.
Representation specific implementations in derived classes. value_set_pointer currently a stub.
483f564
to
11880d1
Compare
11880d1
to
6f2f117
Compare
617a5b5
to
908e599
Compare
We can pick up the special case for pointer addition in abstract_object::expression_transform.
908e599
to
4844d22
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.
Thanks for removing the changes to util/
I think it is a better PR for the extra passes.
Pointer arithmetic fixes
(p - q)
correctly, whenp
andq
point to the same base objectAssertion is now SUCCESS, when previously it was UNKNOWN.
A pointer difference or comparison expression is slightly unusual - the type of the expression is a number (or boolean), but the two operands are pointer types. Generally, the expression type is the same as the first operand (if not all of them). Because of this type mismatch, the abstract environment was dispatching the expression to the wrong abstract type for evaluation, so the result was TOP and therefore unhelpful.
The changes to evaluate pointer differences are small - an additional case in
abstract_environmentt::eval
to pick up a pointer difference and dispatch it toabstract_pointer_object
, and then the corresponding changes inabstract_pointer_object
to calculate the difference.Pointer comparisons are a little more involved. Again, we have an additional case in
abstract_environmentt::eval
to dispatch the expression toabstract_pointer_object
. If the two pointers point to the same base object we can rewrite the comparison in terms of the pointer offset and evaluate that. If the two pointers point to different objects, we can evaluate == and !=, but other comparisons go top.