-
Notifications
You must be signed in to change notification settings - Fork 273
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
goto-instrument --remove-function-body #730
Merged
Merged
Changes from all commits
Commits
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 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <assert.h> | ||
|
||
int foo() | ||
{ | ||
int a; | ||
assert(a>0); | ||
return a; | ||
} | ||
|
||
int bar() | ||
{ | ||
int b; | ||
assert(b>0); | ||
return b; | ||
} | ||
|
||
int main() | ||
{ | ||
foo(); | ||
bar(); | ||
} |
10 changes: 10 additions & 0 deletions
10
regression/goto-instrument/remove-function-body1/test.desc
This file contains 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CORE | ||
main.c | ||
--remove-function-body foo --remove-function-body bar | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
^warning: ignoring | ||
^bar | ||
^foo |
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -90,6 +90,7 @@ Author: Daniel Kroening, [email protected] | |
#include "unwind.h" | ||
#include "model_argc_argv.h" | ||
#include "undefined_functions.h" | ||
#include "remove_function.h" | ||
|
||
/*******************************************************************\ | ||
|
||
|
@@ -1034,6 +1035,15 @@ void goto_instrument_parse_optionst::instrument_goto_program() | |
throw 0; | ||
} | ||
|
||
if(cmdline.isset("remove-function-body")) | ||
{ | ||
remove_functions( | ||
symbol_table, | ||
goto_functions, | ||
cmdline.get_values("remove-function-body"), | ||
get_message_handler()); | ||
} | ||
|
||
// we add the library in some cases, as some analyses benefit | ||
|
||
if(cmdline.isset("add-library") || | ||
|
@@ -1634,6 +1644,8 @@ void goto_instrument_parse_optionst::help() | |
HELP_REMOVE_CONST_FUNCTION_POINTERS | ||
" --add-library add models of C library functions\n" | ||
" --model-argc-argv <n> model up to <n> command line arguments\n" | ||
// NOLINTNEXTLINE(whitespace/line_length) | ||
" --remove-function-body <f> remove the implementation of function <f> (may be repeated)\n" | ||
"\n" | ||
"Other options:\n" | ||
" --use-system-headers with --dump-c/--dump-cpp: generate C source with includes\n" // NOLINT(*) | ||
|
This file contains 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 |
---|---|---|
|
@@ -72,7 +72,8 @@ Author: Daniel Kroening, [email protected] | |
"(z3)(add-library)(show-dependence-graph)" \ | ||
"(horn)(skip-loops):(apply-code-contracts)(model-argc-argv):" \ | ||
"(show-threaded)(list-calls-args)(print-path-lengths)" \ | ||
"(undefined-function-is-assume-false)" | ||
"(undefined-function-is-assume-false)" \ | ||
"(remove-function-body):" | ||
|
||
class goto_instrument_parse_optionst: | ||
public parse_options_baset, | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Remove function definition | ||
|
||
Author: Michael Tautschnig | ||
|
||
Date: April 2017 | ||
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. This comment block doesn't normally have the date, how come we've added it here? 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.
Seems it's all very much inconsistent. |
||
|
||
\*******************************************************************/ | ||
|
||
#include "remove_function.h" | ||
|
||
#include <util/message.h> | ||
|
||
#include <goto-programs/goto_functions.h> | ||
|
||
/*******************************************************************\ | ||
|
||
Function: remove_function | ||
|
||
Inputs: | ||
symbol_table Input symbol table to be modified | ||
goto_functions Input functions to be modified | ||
identifier Function to be removed | ||
message_handler Error/status output | ||
|
||
Outputs: | ||
|
||
Purpose: Remove the body of function "identifier" such that an | ||
analysis will treat it as a side-effect free function with | ||
non-deterministic return value. | ||
|
||
\*******************************************************************/ | ||
|
||
void remove_function( | ||
symbol_tablet &symbol_table, | ||
goto_functionst &goto_functions, | ||
const irep_idt &identifier, | ||
message_handlert &message_handler) | ||
{ | ||
messaget message(message_handler); | ||
|
||
goto_functionst::function_mapt::iterator entry= | ||
goto_functions.function_map.find(identifier); | ||
|
||
if(entry==goto_functions.function_map.end()) | ||
{ | ||
message.error() << "No function " << identifier | ||
<< " in goto program" << messaget::eom; | ||
return; | ||
} | ||
else if(entry->second.is_inlined()) | ||
{ | ||
message.warning() << "Function " << identifier << " is inlined, " | ||
<< "instantiations will not be removed" | ||
<< messaget::eom; | ||
} | ||
|
||
if(entry->second.body_available()) | ||
{ | ||
message.status() << "Removing body of " << identifier | ||
<< messaget::eom; | ||
entry->second.clear(); | ||
symbol_table.lookup(identifier).value.make_nil(); | ||
} | ||
} | ||
|
||
/*******************************************************************\ | ||
|
||
Function: remove_functions | ||
|
||
Inputs: | ||
symbol_table Input symbol table to be modified | ||
goto_functions Input functions to be modified | ||
names List of functions to be removed | ||
message_handler Error/status output | ||
|
||
Outputs: | ||
|
||
Purpose: Remove the body of all functions listed in "names" such that | ||
an analysis will treat it as a side-effect free function with | ||
non-deterministic return value. | ||
|
||
\*******************************************************************/ | ||
|
||
void remove_functions( | ||
symbol_tablet &symbol_table, | ||
goto_functionst &goto_functions, | ||
const std::list<std::string> &names, | ||
message_handlert &message_handler) | ||
{ | ||
for(const auto &f : names) | ||
remove_function(symbol_table, goto_functions, f, message_handler); | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Remove function definition | ||
|
||
Author: Michael Tautschnig | ||
|
||
Date: April 2017 | ||
|
||
\*******************************************************************/ | ||
|
||
#ifndef CPROVER_GOTO_INSTRUMENT_REMOVE_FUNCTION_H | ||
#define CPROVER_GOTO_INSTRUMENT_REMOVE_FUNCTION_H | ||
|
||
#include <list> | ||
#include <string> | ||
|
||
#include <util/irep.h> | ||
|
||
class goto_functionst; | ||
class message_handlert; | ||
class symbol_tablet; | ||
|
||
void remove_function( | ||
symbol_tablet &symbol_table, | ||
goto_functionst &goto_functions, | ||
const irep_idt &identifier, | ||
message_handlert &message_handler); | ||
|
||
void remove_functions( | ||
symbol_tablet &symbol_table, | ||
goto_functionst &goto_functions, | ||
const std::list<std::string> &names, | ||
message_handlert &message_handler); | ||
|
||
#endif // CPROVER_GOTO_INSTRUMENT_REMOVE_FUNCTION_H |
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.
I appreciate that it is hard to actually test anything from the output, but it might be good if we could run
--show-goto-functions
on the output and check that bar is really removed?Alternatively, if you grab #874, it might be relatively easy to add some unit tests for 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 have added patterns that must not be found in test.desc, so I think this is addressed.