-
Notifications
You must be signed in to change notification settings - Fork 269
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
Use goto-analyzer to add assumptions, assertions and code contracts #7964
Draft
martin-cs
wants to merge
2
commits into
diffblue:develop
Choose a base branch
from
martin-cs:feature/goto-analyzer-instrument-task
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,29 @@ | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,8 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include "ai_history.h" | ||
|
||
#include <set> | ||
|
||
// forward reference the abstract interpreter interface | ||
class ai_baset; | ||
|
||
|
@@ -155,15 +157,37 @@ class ai_domain_baset | |
/// Simplifies the expression but keeps it as an l-value | ||
virtual bool ai_simplify_lhs(exprt &condition, const namespacet &ns) const; | ||
|
||
/// Gives a Boolean condition that is true for all values represented by the | ||
/// domain. This allows domains to be converted into program invariants. | ||
virtual exprt to_predicate(void) const | ||
/// Gives a Boolean condition involving expression from the set that | ||
/// is true for all of the states represented by the domain. If the | ||
/// set is empty then the domain can use any expressions in building | ||
/// the condition. This allows domains to be converted into program | ||
/// invariants. | ||
virtual exprt | ||
to_predicate(const std::set<exprt> &, const namespacet &ns) const | ||
{ | ||
// Without knowing what the domain records this is the best that | ||
// can be done. | ||
if(is_bottom()) | ||
return false_exprt(); | ||
else | ||
return true_exprt(); | ||
} | ||
|
||
/// A utility function to convert to generate a predicate without | ||
/// grammar restrictions. | ||
virtual exprt to_predicate(const namespacet &ns) const | ||
{ | ||
std::set<exprt> empty; | ||
return to_predicate(empty, ns); | ||
} | ||
|
||
/// to_predicate for a single expression. | ||
virtual exprt to_predicate(const exprt &e, const namespacet &ns) const | ||
{ | ||
std::set<exprt> single; | ||
single.insert(e); | ||
return to_predicate(single, ns); | ||
} | ||
}; | ||
|
||
// No virtual interface is complete without a factory! | ||
|
Oops, something went wrong.
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.
Gives a Boolean condition involving expressions from the given set that... ?