forked from diffblue/cbmc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a task to goto-analyzer to instrument the program with invariants
- Loading branch information
Showing
19 changed files
with
796 additions
and
3 deletions.
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
14 changes: 14 additions & 0 deletions
14
regression/goto-analyzer/instrument-basic/after_goto_not_taken.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,14 @@ | ||
CORE | ||
main.c | ||
--instrument out.gb --instrument-targets after_goto_not_taken --verbosity 9 --vsd | ||
activate-multi-line-match | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^Instrumenting example_function\nInstruction \d+ because after_goto_not_taken... single history... condition is example_function::argument = 1 ∧ true_from_calling_context = 1... added as assumption$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
Testing instrumenting at after gotos that are not taken (i.e. the "other" branch that is not a goto_target) | ||
|
||
|
||
|
13 changes: 13 additions & 0 deletions
13
regression/goto-analyzer/instrument-basic/any_goto_target.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,13 @@ | ||
CORE | ||
main.c | ||
--instrument out.gb --instrument-targets any_goto_target --verbosity 9 --vsd | ||
activate-multi-line-match | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^Instrumenting example_function\nInstruction \d+ because any_goto_target... single history... condition is example_function::argument = 1 ∧ true_from_calling_context = 1... added as assumption\nInstruction \d+ because any_goto_target... single history... condition is example_function::argument = 1 ∧ true_from_calling_context = 1 ∧ \(10 ≤ example_function::1::1::i ∧ example_function::1::1::i ≤ max_value\)... added as assumption$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
Testing instrumenting at goto targets | ||
|
||
|
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,14 @@ | ||
CORE | ||
main.c | ||
--instrument out.gb --instrument-targets function_call=assert,function_start=assume,function_end=assert,function_return=assume --verbosity 9 --vsd | ||
activate-multi-line-match | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^Instrumenting main\nInstruction \d+ because function_return... single history... condition is main::1::argument_input = 1 ∧ true_from_calling_context = 1 ∧ \(0 ≤ main::argc ∧ main::argc ≤ max_value\)... added as assumption\nInstruction \d+ because function_end... single history... condition is main#return_value = 0 ∧ true_from_calling_context = 1 ∧ \(0 ≤ main::argc ∧ main::argc ≤ max_value\)... added as assertion\nInstruction \d+ because function_start... single history... condition is true_from_calling_context = 0 ∧ \(0 ≤ main::argc ∧ main::argc ≤ max_value\)... added as assumption\nInstruction \d+ because function_call... single history... condition is main::1::argument_input = 1 ∧ true_from_calling_context = 1 ∧ \(0 ≤ main::argc ∧ main::argc ≤ max_value\)... added as assertion$ | ||
^Instrumenting example_function\nInstruction \d+ because function_end... single history... condition is example_function::argument = 1 ∧ true_from_calling_context = 1... added as assertion\nInstruction \d+ because function_start... single history... condition is example_function::argument = 1 ∧ true_from_calling_context = 1... added as assumption$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
Testing the addition of assertions in a way that mimics the use of contracts | ||
|
||
|
13 changes: 13 additions & 0 deletions
13
regression/goto-analyzer/instrument-basic/backwards_goto_target.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,13 @@ | ||
CORE | ||
main.c | ||
--instrument out.gb --instrument-targets backwards_goto_target --verbosity 9 --vsd | ||
activate-multi-line-match | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^Instrumenting example_function\nInstruction \d+ because backwards_goto_target... single history... condition is example_function::argument = 1 ∧ true_from_calling_context = 1... added as assumption$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
Testing instrumenting at backwards goto targets | ||
|
||
|
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,13 @@ | ||
CORE | ||
main.c | ||
--instrument out.gb --verbosity 9 --vsd | ||
activate-multi-line-match | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^Instrumenting main\nInstruction \d+ because function_start... single history... condition is true_from_calling_context = 0 ∧ \(0 ≤ main::argc ∧ main::argc ≤ max_value\)... added as assumption\nInstruction \d+ because function_return... single history... condition is main::1::argument_input = 1 ∧ true_from_calling_context = 1 ∧ \(0 ≤ main::argc ∧ main::argc ≤ max_value\)... added as assumption$ | ||
^Instrumenting example_function\nInstruction \d+ because function_start... single history... condition is example_function::argument = 1 ∧ true_from_calling_context = 1... added as assumption\nInstruction \d+ because backwards_goto_target... single history... condition is example_function::argument = 1 ∧ true_from_calling_context = 1... added as assumption$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
Testing the default options of instrumentation with goto-analyze | ||
|
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,12 @@ | ||
CORE | ||
main.c | ||
--instrument out.gb --instrument-targets ensures --verbosity 9 --vsd | ||
activate-multi-line-match | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^Instrumenting example_function\nAdd ensures contract... single history... condition is example_function::argument = 1 ∧ true_from_calling_context = 1... added as contract$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
Testing instrumenting add ensures contract | ||
|
13 changes: 13 additions & 0 deletions
13
regression/goto-analyzer/instrument-basic/function_call.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,13 @@ | ||
CORE | ||
main.c | ||
--instrument out.gb --instrument-targets function_call --verbosity 9 --vsd | ||
activate-multi-line-match | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^Instrumenting main\nInstruction \d+ because function_call... single history... condition is main::1::argument_input = 1 ∧ true_from_calling_context = 1 ∧ \(0 ≤ main::argc ∧ main::argc ≤ max_value\)... added as assumption$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
Testing instrumenting at function call | ||
|
||
|
14 changes: 14 additions & 0 deletions
14
regression/goto-analyzer/instrument-basic/function_end.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,14 @@ | ||
CORE | ||
main.c | ||
--instrument out.gb --instrument-targets function_end --verbosity 9 --vsd | ||
activate-multi-line-match | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^Instrumenting main\nInstruction \d+ because function_end... single history... condition is main#return_value = 0 ∧ true_from_calling_context = 1 ∧ \(0 ≤ main::argc ∧ main::argc ≤ max_value\)... added as assumption$ | ||
^Instrumenting example_function\nInstruction \d+ because function_end... single history... condition is example_function::argument = 1 ∧ true_from_calling_context = 1... added as assumption$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
Testing instrumenting at the function end | ||
|
||
|
13 changes: 13 additions & 0 deletions
13
regression/goto-analyzer/instrument-basic/function_return.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,13 @@ | ||
CORE | ||
main.c | ||
--instrument out.gb --instrument-targets function_return --verbosity 9 --vsd | ||
activate-multi-line-match | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^Instrumenting main\nInstruction \d+ because function_return... single history... condition is main::1::argument_input = 1 ∧ true_from_calling_context = 1 ∧ \(0 ≤ main::argc ∧ main::argc ≤ max_value\)... added as assumption$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
Testing instrumenting at function return | ||
|
||
|
14 changes: 14 additions & 0 deletions
14
regression/goto-analyzer/instrument-basic/function_start.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,14 @@ | ||
CORE | ||
main.c | ||
--instrument out.gb --instrument-targets function_start --verbosity 9 --vsd | ||
activate-multi-line-match | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^Instrumenting main\nInstruction \d+ because function_start... single history... condition is true_from_calling_context = 0 ∧ \(0 ≤ main::argc ∧ main::argc ≤ max_value\)... added as assumption$ | ||
^Instrumenting example_function\nInstruction \d+ because function_start... single history... condition is example_function::argument = 1 ∧ true_from_calling_context = 1... added as assumption$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
Testing instrumenting at the function start | ||
|
||
|
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,26 @@ | ||
int true_from_calling_context = 0; | ||
|
||
int example_function(int argument) { | ||
int local = argument + 1; | ||
int location = 1; | ||
|
||
for (int i = 0; i < 10; ++i) { | ||
location = 2; | ||
++local; | ||
} | ||
|
||
location = 3; | ||
++local; | ||
|
||
return location + local; | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
true_from_calling_context = 1; | ||
|
||
int argument_input = 1; | ||
|
||
int ret = example_function(argument_input); | ||
|
||
return 0; | ||
} |
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,14 @@ | ||
CORE | ||
main.c | ||
--instrument out.gb --instrument-targets requires --verbosity 9 --vsd | ||
activate-multi-line-match | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^Instrumenting example_function\nAdd requires contract... single history... condition is example_function::argument = 1 ∧ true_from_calling_context = 1... added as contract$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
Testing instrumenting add requires contract | ||
|
||
|
||
|
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 |
---|---|---|
|
@@ -34,6 +34,7 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include "build_analyzer.h" | ||
#include "show_on_source.h" | ||
#include "static_instrument.h" | ||
#include "static_show_domain.h" | ||
#include "static_simplifier.h" | ||
#include "static_verifier.h" | ||
|
@@ -160,6 +161,18 @@ void goto_analyzer_parse_optionst::get_command_line_options(optionst &options) | |
"simplify-slicing", | ||
!(cmdline.isset("no-simplify-slicing"))); | ||
} | ||
else if(cmdline.isset("instrument")) | ||
{ | ||
if(cmdline.get_value("instrument") == "-") | ||
throw invalid_command_line_argument_exceptiont( | ||
"cannot output goto binary to stdout", "--instrument"); | ||
|
||
options.set_option("instrument", true); | ||
options.set_option("outfile", cmdline.get_value("instrument")); | ||
options.set_option("general-analysis", true); | ||
options.set_option( | ||
"instrument-targets", cmdline.get_value("instrument-targets")); | ||
} | ||
else if(cmdline.isset("show-intervals")) | ||
{ | ||
// For backwards compatibility | ||
|
@@ -623,6 +636,24 @@ int goto_analyzer_parse_optionst::perform_analysis(const optionst &options) | |
result = static_simplifier( | ||
goto_model, *analyzer, options, ui_message_handler, out); | ||
} | ||
else if(options.get_bool_option("instrument")) | ||
{ | ||
PRECONDITION(!outfile.empty() && outfile != "-"); | ||
output_stream.close(); | ||
output_stream.open(outfile, std::ios::binary); | ||
if(options.is_set("instrument-targets") && | ||
options.get_option("instrument-targets") != "") | ||
{ | ||
result = static_instrument( | ||
goto_model, *analyzer, options.get_option("instrument-targets"), ui_message_handler, out); | ||
} | ||
else | ||
{ | ||
// A reasonably sane set of defaults | ||
result = static_instrument( | ||
goto_model, *analyzer, "function_start=assume,function_return=assume,backwards_goto_target=assume", ui_message_handler, out); | ||
} | ||
} | ||
else if(options.get_bool_option("unreachable-instructions")) | ||
{ | ||
result = static_unreachable_instructions(goto_model, | ||
|
@@ -705,6 +736,8 @@ void goto_analyzer_parse_optionst::help() | |
" program\n" | ||
" {y--no-simplify-slicing} \t do not remove instructions from which no" | ||
" property can be reached (use with {y--simplify})\n" | ||
" {y--instrument} {ufile_name} \t use the abstract domains to generate annotations\n" | ||
" {y--instrument-targets} {ulist} \t where to annotate and what annotations to use\n" | ||
" {y--unreachable-instructions} \t list dead code\n" | ||
" {y--unreachable-functions} \t list functions unreachable from the entry" | ||
" point\n" | ||
|
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
Oops, something went wrong.