-
Notifications
You must be signed in to change notification settings - Fork 277
Improve harness generated code readability #5087
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
Merged
hannes-steffenhagen-diffblue
merged 4 commits into
diffblue:develop
from
xbauch:feature/better-harness
Nov 1, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
32cde1b
Convert the whole model rather than a single function
petr-bauch 3674dcc
Clean-up harnesses in testing symbol init-ability
petr-bauch d0212b9
Helper functions to simplify manipulating symbols
petr-bauch 9ca0824
Rewrite the recursive constructors
petr-bauch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
regression/goto-harness/pointer-to-array-function-parameters/test.desc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
CORE | ||
test.c | ||
--harness-type call-function --function test --treat-pointer-as-array arr | ||
\[test.pointer_dereference.\d+\] line \d+ dereference failure: pointer outside object bounds in arr\[\(signed( long)* int\)0\]: SUCCESS | ||
\[test.pointer_dereference.\d+\] line \d+ dereference failure: pointer outside object bounds in arr\[\(signed( long)* int\)10\]: FAILURE | ||
\[test.pointer_dereference.\d+\] line \d+ dereference failure: pointer outside dynamic object bounds in arr\[\(signed( long)* int\)0\]: SUCCESS | ||
\[test.pointer_dereference.\d+\] line \d+ dereference failure: pointer outside dynamic object bounds in arr\[\(signed( long)* int\)10\]: FAILURE | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
-- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,15 +10,15 @@ Author: Diffblue Ltd. | |
|
||
#include <util/allocate_objects.h> | ||
#include <util/arith_tools.h> | ||
#include <util/c_types.h> | ||
#include <util/exception_utils.h> | ||
#include <util/prefix.h> | ||
#include <util/std_code.h> | ||
#include <util/std_expr.h> | ||
#include <util/string2int.h> | ||
#include <util/string_utils.h> | ||
#include <util/ui_message.h> | ||
|
||
#include <goto-programs/goto_convert.h> | ||
#include <goto-programs/goto_convert_functions.h> | ||
#include <goto-programs/goto_model.h> | ||
|
||
#include <algorithm> | ||
|
@@ -54,6 +54,8 @@ struct function_call_harness_generatort::implt | |
std::map<irep_idt, irep_idt> function_argument_to_associated_array_size; | ||
std::map<irep_idt, irep_idt> function_parameter_to_associated_array_size; | ||
|
||
std::set<symbol_exprt> global_pointers; | ||
|
||
/// \see goto_harness_generatort::generate | ||
void generate(goto_modelt &goto_model, const irep_idt &harness_function_name); | ||
/// Iterate over the symbol table and generate initialisation code for | ||
|
@@ -195,6 +197,11 @@ void function_call_harness_generatort::implt::generate( | |
|
||
generate_nondet_globals(function_body); | ||
call_function(arguments, function_body); | ||
for(const auto &global_pointer : global_pointers) | ||
{ | ||
function_body.add(code_function_callt{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I thought you'd have to pass more than one parameter here sometimes? |
||
recursive_initialization->get_free_function(), {global_pointer}}); | ||
} | ||
add_harness_function_to_goto_model(std::move(function_body)); | ||
} | ||
|
||
|
@@ -213,10 +220,7 @@ void function_call_harness_generatort::implt::generate_nondet_globals( | |
for(const auto &symbol_table_entry : *symbol_table) | ||
{ | ||
const auto &symbol = symbol_table_entry.second; | ||
if( | ||
symbol.is_static_lifetime && symbol.is_lvalue && | ||
symbol.type.id() != ID_code && | ||
!has_prefix(id2string(symbol.name), CPROVER_PREFIX)) | ||
if(recursive_initialization->is_initialization_allowed(symbol)) | ||
{ | ||
globals.push_back(symbol.symbol_expr()); | ||
} | ||
|
@@ -232,7 +236,10 @@ void function_call_harness_generatort::implt::generate_initialisation_code_for( | |
code_blockt &block, | ||
const exprt &lhs) | ||
{ | ||
recursive_initialization->initialize(lhs, 0, {}, block); | ||
recursive_initialization->initialize( | ||
lhs, from_integer(0, signed_int_type()), block); | ||
if(lhs.type().id() == ID_pointer) | ||
global_pointers.insert(to_symbol_expr(lhs)); | ||
} | ||
|
||
void function_call_harness_generatort::validate_options( | ||
|
@@ -300,14 +307,7 @@ void function_call_harness_generatort::implt:: | |
symbol_table->lookup_ref(harness_function_name); | ||
goto_functions->function_map[harness_function_name].type = | ||
to_code_type(generated_harness.type); | ||
auto &body = goto_functions->function_map[harness_function_name].body; | ||
goto_convert( | ||
static_cast<const codet &>(generated_harness.value), | ||
*symbol_table, | ||
body, | ||
*message_handler, | ||
function_to_call.mode); | ||
body.add(goto_programt::make_end_function()); | ||
goto_convert(*symbol_table, *goto_functions, *message_handler); | ||
} | ||
|
||
code_function_callt::argumentst | ||
|
@@ -377,6 +377,8 @@ void function_call_harness_generatort::implt::call_function( | |
for(auto const &argument : arguments) | ||
{ | ||
generate_initialisation_code_for(function_body, argument); | ||
if(argument.type().id() == ID_pointer) | ||
global_pointers.insert(to_symbol_expr(argument)); | ||
} | ||
code_function_callt function_call{function_to_call.symbol_expr(), | ||
std::move(arguments)}; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
⛏️ braces please
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.
Added.