-
Notifications
You must be signed in to change notification settings - Fork 277
Fix for getting values of pointers in traces in new SMT backend #6831
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
NlightNFotis
merged 4 commits into
diffblue:develop
from
NlightNFotis:pointer_val_in_trace_fix
Apr 27, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5cdccdd
Add getting of pointer values in new SMT2 decision procedure
NlightNFotis 49645bc
Add regression test for matching against pointer values in traces of …
NlightNFotis 53e2aa4
Add regression test for pointer address being found in the trace in n…
NlightNFotis 691a3df
Add unit tests for pointer support in bit_vector_constant_termt visit
NlightNFotis 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
int main() | ||
{ | ||
int *a; | ||
int *b = 0; | ||
int *c; | ||
__CPROVER_assume(c != 0); | ||
|
||
__CPROVER_assert( | ||
a != b, "should fail because a can be any pointer val, including NULL"); | ||
__CPROVER_assert( | ||
a != c, "should fail because a and c can point to same object"); | ||
} |
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,12 @@ | ||
CORE | ||
pointer_values.c | ||
--trace | ||
\[main\.assertion\.1\] line \d+ should fail because a can be any pointer val, including NULL: FAILURE | ||
\[main\.assertion\.2\] line \d+ should fail because a and c can point to same object: FAILURE | ||
a=\(\(signed int \*\)NULL\) | ||
c=\(signed int \*\)1 | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
-- | ||
-- | ||
Test printing of NULL pointer values in trace. |
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,8 @@ | ||
int main() | ||
{ | ||
int *a; | ||
int *b; | ||
__CPROVER_assume(a == 0xDEADBEEF); | ||
|
||
__CPROVER_assert(a != b, "should fail as b can also be assigned 0xDEADBEEF"); | ||
} |
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,12 @@ | ||
CORE | ||
pointer_values_2.c | ||
--trace --slice-formula | ||
\[main\.assertion\.1\] line \d should fail as b can also be assigned 0xDEADBEEF: FAILURE | ||
a=\(signed int \*\)3735928559 | ||
b=\(signed int \*\)3735928559 | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
-- | ||
-- | ||
3735928559 is the decimal value of the hex constant 0xDEADBEEF that | ||
the pointer is assumed to point to in this example. |
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,15 +1,15 @@ | ||
// Author: Diffblue Ltd. | ||
|
||
#include <solvers/smt2_incremental/construct_value_expr_from_smt.h> | ||
|
||
#include <solvers/smt2_incremental/smt_terms.h> | ||
|
||
#include <util/arith_tools.h> | ||
#include <util/bitvector_types.h> | ||
#include <util/pointer_expr.h> | ||
#include <util/std_expr.h> | ||
#include <util/std_types.h> | ||
#include <util/type.h> | ||
|
||
#include <solvers/smt2_incremental/construct_value_expr_from_smt.h> | ||
#include <solvers/smt2_incremental/smt_terms.h> | ||
|
||
class value_expr_from_smt_factoryt : public smt_term_const_downcast_visitort | ||
{ | ||
private: | ||
|
@@ -37,13 +37,35 @@ class value_expr_from_smt_factoryt : public smt_term_const_downcast_visitort | |
|
||
void visit(const smt_bit_vector_constant_termt &bit_vector_constant) override | ||
{ | ||
const auto sort_width = bit_vector_constant.get_sort().bit_width(); | ||
if( | ||
const auto pointer_type = | ||
type_try_dynamic_cast<pointer_typet>(type_to_construct)) | ||
{ | ||
INVARIANT( | ||
pointer_type->get_width() == sort_width, | ||
"Width of smt bit vector term must match the width of pointer type."); | ||
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 change appears to have been squashed into the wrong commit. |
||
if(bit_vector_constant.value() == 0) | ||
{ | ||
result = null_pointer_exprt{*pointer_type}; | ||
} | ||
else | ||
{ | ||
// The reason we are manually constructing a constant_exprt here is a | ||
// limitation in the design of `from_integer`, which only allows it to | ||
// be used with pointer values of 0 (null pointers). | ||
result = constant_exprt{ | ||
integer2bvrep(bit_vector_constant.value(), sort_width), | ||
*pointer_type}; | ||
} | ||
return; | ||
} | ||
if( | ||
const auto bitvector_type = | ||
type_try_dynamic_cast<bitvector_typet>(type_to_construct)) | ||
{ | ||
INVARIANT( | ||
bitvector_type->get_width() == | ||
bit_vector_constant.get_sort().bit_width(), | ||
bitvector_type->get_width() == sort_width, | ||
"Width of smt bit vector term must match the width of bit vector " | ||
"type."); | ||
result = from_integer(bit_vector_constant.value(), type_to_construct); | ||
|
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
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.
⛏️ Missing test description - "Test printing of NULL pointer values in trace."