-
Notifications
You must be signed in to change notification settings - Fork 284
VSD - pointers to heap allocations #6218
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 - pointers to heap allocations #6218
Conversation
5c95d44 to
0fbd46a
Compare
Codecov Report
@@ Coverage Diff @@
## develop #6218 +/- ##
========================================
Coverage 76.18% 76.19%
========================================
Files 1484 1484
Lines 162092 162155 +63
========================================
+ Hits 123495 123558 +63
Misses 38597 38597
Continue to review full report at Codecov.
|
4176f59 to
0d7d37f
Compare
| const abstract_environmentt &environment, | ||
| const namespacet &ns) const | ||
| { | ||
| INVARIANT(is_void_pointer(type()), "Only allow pointer casting from void*"); |
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 feel kind of conflicted about this. In some ways it should not be an INVARIANT because it can be triggered by a user but also, at the moment we really aren't handling this case. Could we return a TOP pointer of the correct type? Reads from that should give TOP and writes to it could call havoc()?
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 similarly conflicted. Right now, the call to typecast() is itself guarded so that it will never be called if this invariant will fire
if(expr.id() == ID_typecast)
{
const typecast_exprt &tce = to_typecast_expr(expr);
if(tce.op().id() == ID_symbol && is_void_pointer(tce.op().type()))
Consequently existing typecasts, of which there are a handful, will evaluate as they do at the moment. I suppose this invariant is more of warning for future care than a guard against wacky corner cases.
| const abstract_environmentt &environment, | ||
| const namespacet &ns) const | ||
| { | ||
| INVARIANT(is_void_pointer(type()), "Only allow pointer casting from void*"); |
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.
As above.
src/analyses/variable-sensitivity/constant_pointer_abstract_object.cpp
Outdated
Show resolved
Hide resolved
Create a special 'heap allocation' placeholder expression. Extend write_stack to be able to store that expression.
That's the expr.type() rather than the representation class.
We can't ensure the modified pointer object will be properly assigned back to its symbol if we wait until first write. If we defer then modified pointer may, or may not, be assigned depending on how the write is expressed *p = 1; // good :) p[0] = 1; // bad :(
I based my code in the previous commit on this code, but then found it caused a type error. This leads me to believe that while this current code path may not be called in normal usage, it is in fact a latent bug. I believe this change is correct.
This feels like the right place for this, and also gives future options for configuration/customisation.
6651b77 to
1a6a422
Compare
Extends the variable sensitivity domain to be able to track heap allocated memory.
Within the goto-programs the heap allocation instruction is
ALLOCATE(malloc_size, 0 != 0). Within the vsd, this is an expression of typeID_side_effectwith a statement ofID_allocate. When we eval this expression, we create a pointer object with a 'heap-object' placeholder expression. There's a little song and dance to propagate through the pointer type casts returns from malloc are subject to, but we can return 'heap-object' pointer back out.When we assign pointer to a heap allocation to its symbol, we now know that actual (C) type of the object. We replace the 'heap object' placeholder with an array abstract object. The pointer abstract object can now act exactly as normal.