-
Notifications
You must be signed in to change notification settings - Fork 273
Factor out object allocation from object factories [blocks: #3455] #3443
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
Factor out object allocation from object factories [blocks: #3455] #3443
Conversation
/// \param allocate_type: Type of the object allocated | ||
/// \param alloc_type: Allocation type (global, local or dynamic) | ||
/// \return An expression denoting the address of the newly allocated object. | ||
exprt allocate_objectst::allocate_object( |
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 would expect doxygen to complain about not describing the symbols_created
.
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 should probably have a full TG bump before merging (I will make after the preceding PR is merged) - also does this mean that the cprover start for C programs will do non-det init of structs like how they are handled in Java? Or have I got the wrong end of the stick? If so - very exciting!
@thk123 Getting something like that to work for structs and arrays is indeed the intention here |
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.
LGTM, I think the allocate commits should be squashed though, they don't make much sense in isolatin.
c1e0d0c
to
3e21c82
Compare
3e21c82
to
4c17764
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: 4c17764).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/92382053
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.
Recursive nondet init of pointers to structs [blocks: #3443]
4c17764
to
9c1348b
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: 9c1348b).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/92725646
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.
LGTM
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.
Overall ok, I'm just concerned about terminology.
src/util/allocate_objects.cpp
Outdated
|
||
#include <util/c_types.h> | ||
#include <util/fresh_symbol.h> | ||
#include <util/pointer_offset_size.h> |
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.
Nit pick: within the folder we generally seem to use "..."
instead of <...>
src/util/allocate_objects.cpp
Outdated
#include <util/fresh_symbol.h> | ||
#include <util/pointer_offset_size.h> | ||
|
||
/// Installs a new symbol in the symbol table, pushing the corresponding |
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.
What is the input here that controls what symbol is to be created?
src/util/allocate_objects.cpp
Outdated
assignments, target_expr, allocate_type, false, symbols_created); | ||
break; | ||
|
||
case allocation_typet::GLOBAL: |
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 not entirely happy with this terminology: the lifetime of an object vs its access scope are possibly different. In fact I don't know which one you are after for this one here. Is it about placing a symbol in the global namespace, or is it about allocation?
src/util/allocate_objects.cpp
Outdated
/// \param assignments: The code block to add code to. | ||
/// \param target_expr: The expression which we are allocating a symbol for. | ||
/// \param allocate_type: Type of the object allocated | ||
/// \param alloc_type: Allocation type (global, local or dynamic) |
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.
See also below: I'm used to static, stack, and heap allocation. The adjectives you use I would associate with "declaration," not "allocation." ("dynamic" is a weird one either way, but of course it so happens that it is used in CProver.)
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.
Yeah this is a bit tricky terminology-wise since as you mentioned the access scope, lifetime, and the location of the allocated memory are different things.
The way I see it is that the main thing allocate_objectst
does is generate code that allocates objects (irrespective of where the memory allocated for those objects might be located physically). The code to allocate the objects does so by either declaring a local variable (local scope, automatic lifetime), global variable (global scope, static lifetime), or using ALLOCATE()
(dynamic).
I was thinking of renaming the members of allocation_typet
to AUTOMATIC_LOCAL
, STATIC_GLOBAL
, and DYNAMIC
. Would you be ok with that?
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.
Would lifetimet
be the most suitable name (instead of allocation_typet
)? The suggested member names sound good to me, but mostly it's the use of "type" that makes me worried (hence suggesting lifetimet
).
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.
Yeah, liftetimet
sounds good to me. I'll change it to that.
src/util/allocate_objects.cpp
Outdated
/// | ||
/// \param assignments: Code block to which the necessary code is added | ||
/// \param target_expr: Expression to which the necessary memory will be | ||
/// allocated, its type should be pointer to `allocate_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.
I don't think you can allocate memory to an expression? Unless you are talking about the storage required by the syntax tree.
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.
How about "A pointer to the allocated memory will be assigned to this (lvalue) expression"?
src/util/allocate_objects.cpp
Outdated
/// allocated, its type should be pointer to `allocate_type` | ||
/// \param allocate_type: Type of the object allocated | ||
/// \param static_lifetime: If `true` a global object will be created, if | ||
/// `false` a local object will be created |
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.
Ok, so "local" vs "global" is about the lifetime?
src/util/allocate_objects.cpp
Outdated
if(!base_type_eq(allocate_type, target_expr.type().subtype(), ns)) | ||
{ | ||
aoe = typecast_exprt(aoe, target_expr.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.
Not exactly the same (because it uses plain equality), but still: I'd go for typecast_exprt::conditional_cast
.
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 also think it's likely that nearly-matching types (except at the very top level) may trip later passes into introducing (e.g.) unnecessary byte-extract operations
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.
Also this (potentially over-eager) typecast omission is a change in behaviour compared to the old code AFAICT; I'd suggest in that case it would want testing with something which is base_type_eq
but not type_eq
(e.g. structs whose fields differ in using a symbol vs. a struct type for one of the members)
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.
Ok, I've changed it to use typecast_exprt::conditional_cast
(the original code used ns.follow
on both types followed by comparing them via ==
to figure out whether a typecast should be introduced).
src/util/allocate_objects.cpp
Outdated
{ | ||
malloc_symbol_expr = | ||
typecast_exprt(malloc_symbol_expr, target_expr.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.
As above
Unassigned for now as waiting for response re: |
8b04439
to
f071684
Compare
0a1f50f
to
68b3a4f
Compare
68b3a4f
to
fda069a
Compare
fda069a
to
890be45
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: 890be45).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/95134382
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.
The PR factors out the object allocation code from the Java object factory into a separate class
allocate_objectst
that can be used by both the C and Java object factories.