-
Notifications
You must be signed in to change notification settings - Fork 277
Unify havocing codegen within code contracts #6292
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
Merged
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 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
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,10 +1,19 @@ | ||
CORE | ||
main.c | ||
--replace-all-calls-with-contracts | ||
--replace-all-calls-with-contracts _ --pointer-primitive-check | ||
^\[main.assertion.1\] line \d+ assertion b\[0\] == 'a': FAILURE$ | ||
^\[main.assertion.2\] line \d+ assertion b\[1\] == 'b': FAILURE$ | ||
^\[main.assertion.3\] line \d+ assertion b\[2\] == 'c': FAILURE$ | ||
^\[main.assertion.4\] line \d+ assertion b\[3\] == 'd': FAILURE$ | ||
^\[main.assertion.5\] line \d+ assertion b\[0\] == 'a': FAILURE$ | ||
^\[main.assertion.6\] line \d+ assertion b\[1\] == '1': SUCCESS$ | ||
^\[main.assertion.7\] line \d+ assertion b\[2\] == 'c': FAILURE$ | ||
^\[main.assertion.8\] line \d+ assertion b\[3\] == '3': FAILURE$ | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^VERIFICATION FAILED$ | ||
-- | ||
^\[.+\.pointer_primitives\.\d+] line .*: FAILURE$ | ||
-- | ||
Checks whether the values outside the array range specified by the assigns | ||
target are not havocked when calling the associated function. | ||
Checks that entire arrays and fixed single elements are correctly havoced | ||
when functions are replaced by contracts. |
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Utilities for building havoc code for expressions. | ||
|
||
Author: Saswat Padhi, saspadhi@amazon.com | ||
|
||
Date: July 2021 | ||
|
||
\*******************************************************************/ | ||
|
||
/// \file | ||
/// Utilities for building havoc code for expressions | ||
|
||
#include "havoc_utils.h" | ||
|
||
#include <util/arith_tools.h> | ||
#include <util/c_types.h> | ||
#include <util/pointer_expr.h> | ||
|
||
void append_safe_havoc_code_for_expr( | ||
const source_locationt source_location, | ||
const exprt &expr, | ||
goto_programt &dest, | ||
const std::function<void()> &havoc_code_impl) | ||
{ | ||
goto_programt skip_program; | ||
const auto skip_target = | ||
skip_program.add(goto_programt::make_skip(source_location)); | ||
|
||
// for deref expressions, check for validity of underlying pointer, | ||
// and skip havocing if invalid (to avoid spurious pointer deref errors) | ||
if(expr.id() == ID_dereference) | ||
{ | ||
const auto condition = not_exprt(w_ok_exprt( | ||
to_dereference_expr(expr).pointer(), | ||
from_integer(0, unsigned_int_type()))); | ||
dest.add(goto_programt::make_goto(skip_target, condition, source_location)); | ||
} | ||
|
||
havoc_code_impl(); | ||
|
||
// for deref expressions, add the final skip target | ||
if(expr.id() == ID_dereference) | ||
dest.destructive_append(skip_program); | ||
} | ||
|
||
void append_object_havoc_code_for_expr( | ||
const source_locationt source_location, | ||
const exprt &expr, | ||
goto_programt &dest) | ||
{ | ||
append_safe_havoc_code_for_expr(source_location, expr, dest, [&]() { | ||
codet havoc(ID_havoc_object); | ||
havoc.add_source_location() = source_location; | ||
havoc.add_to_operands(expr); | ||
dest.add(goto_programt::make_other(havoc, source_location)); | ||
}); | ||
} | ||
|
||
void append_scalar_havoc_code_for_expr( | ||
const source_locationt source_location, | ||
const exprt &expr, | ||
goto_programt &dest) | ||
{ | ||
append_safe_havoc_code_for_expr(source_location, expr, dest, [&]() { | ||
side_effect_expr_nondett rhs(expr.type(), source_location); | ||
feliperodri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
goto_programt::targett t = dest.add( | ||
goto_programt::make_assignment(expr, std::move(rhs), source_location)); | ||
t->code_nonconst().add_source_location() = source_location; | ||
}); | ||
} | ||
|
||
void append_havoc_code( | ||
const source_locationt source_location, | ||
const modifiest &modifies, | ||
goto_programt &dest) | ||
{ | ||
havoc_utils_is_constantt is_constant(modifies); | ||
for(const auto &expr : modifies) | ||
{ | ||
if(expr.id() == ID_index || expr.id() == ID_dereference) | ||
{ | ||
address_of_exprt address_of_expr(expr); | ||
if(!is_constant(address_of_expr)) | ||
{ | ||
append_object_havoc_code_for_expr( | ||
source_location, address_of_expr, dest); | ||
continue; | ||
} | ||
} | ||
|
||
append_scalar_havoc_code_for_expr(source_location, expr, dest); | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.