-
Notifications
You must be signed in to change notification settings - Fork 274
Function pointer non-det initialisation in goto-harness [depends-on: #5171] #5176
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
Function pointer non-det initialisation in goto-harness [depends-on: #5171] #5176
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.
Looks good.
67edbb6
to
825029a
Compare
Codecov Report
@@ Coverage Diff @@
## develop #5176 +/- ##
===========================================
- Coverage 67.4% 67.33% -0.07%
===========================================
Files 1157 1155 -2
Lines 95166 94736 -430
===========================================
- Hits 64144 63794 -350
+ Misses 31022 30942 -80
Continue to review full report at Codecov.
|
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 825029a).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/135629595
ea06a2f
to
60398e7
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 60398e7).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/136133258
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 64a62d4).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/136162388
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: dfadbc8).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/136177150
@@ -12,6 +12,7 @@ Author: Diffblue Ltd. | |||
#include <util/arith_tools.h> | |||
#include <util/c_types.h> | |||
#include <util/exception_utils.h> | |||
#include <util/prefix.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.
do you still need this? (edit: you do, but somewhere in the 4th commit; no need to reorder because of this.)
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 think it's worth fixing that.
|
||
goto_model.goto_functions.function_map[function_symbol.name].type = | ||
to_code_type(function_symbol.type); | ||
return type_constructor_names[type]; | ||
return type_constructor_names.at(key); |
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.
Is there a reason why this access is checked but the above are not?
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 really, tbh we'd considered refactoring this entire section to avoid multiple lookup of the same key. We only added the .at
because at some point we were hitting a case where keys were missing from the map.
if(expr.id() == ID_symbol) | ||
{ | ||
expr_name = to_symbol_expr(expr).get_identifier(); | ||
is_nullable = initialization_config.potential_null_function_pointers.count( | ||
expr_name.value()); |
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.
Maybe it's idiomatic, but I would prefer count(..) != 0
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 agree that'd be easier to read.
} | ||
|
||
const auto &function_pointer_type = | ||
ns.follow(function_pointer_symbol_pointer->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.
Why do we need to follow the 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.
Symbol types aren't resolved at this point (i.e. in the symbol table). They can't be, otherwise we couldn't correctly print typedefs etc in dump-c.
3922445
to
272477c
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 272477c).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/136582105
@@ -72,10 +72,10 @@ struct function_call_harness_generatort::implt | |||
void ensure_harness_does_not_already_exist(); | |||
/// Update the goto-model with the new harness function. | |||
void add_harness_function_to_goto_model(code_blockt function_body); | |||
/// declare local variables for each of the parameters of the entry function | |||
/// Declare local variables for each of the parameters of the entry function |
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.
44509e4 are good changes, but might be better off in a separate PR (although it’d be annoying to separate out this late I know)
|
||
for(const auto &sym : goto_model.get_symbol_table()) | ||
{ | ||
if(sym.second.type == function_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.
We should probably make this work with the function pointer restriction table stuff we have some time.
typet constructor_type; | ||
bool is_nullable; | ||
bool has_size_parameter; | ||
bool operator<(const constructor_keyt &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.
With C++20 we could just default these ;)
/// \return the body of the constructor | ||
code_blockt build_function_pointer_constructor( | ||
const symbol_exprt &result, | ||
bool is_nullable); |
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 extremely excited about having to pass this is_nullable
argument down all the time, but I can’t think of anything super great either.
/// this specification from that for a global variable of the same name, | ||
/// we prepend the name of the function to the parameter name. However, | ||
/// what is actually being initialised in the implementation is not the | ||
/// parameter itself, but a correspond function argument (local variable |
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.
correspond(ing)
Add error checking (check that the entry function is in the symbol table before the code generation, and make sure that it's present correctly) make sure that doc comments are capitalised, change the signatures of functions to make them stricter in the arguments they accept.
272477c
to
14aeac2
Compare
Also add support for having multiple constructors for the same type with different behaviours and different signatures. We are doing this because we need some types to be sometimes nullable and sometimes not, and for example, for arrays we sometimes need to pass a size parameter and sometimes not.
Add mapping from function pointer argument names to local variable names of the harness so users can specify properties of arguments in terms of the names of the arguments rather than having to rely on internal implementation details of the function harness.
Add a test to make sure that we can distinguish between a parameter and a global function pointer variable with the same name and a test to make sure that we get different type constructors for the same type but with extra attributes.
Move it to recursive_initialization_configt because it's a common option.
14aeac2
to
6b684f7
Compare
This is extending the work done in #5171 of which the first commit of this PR belongs to.