-
Notifications
You must be signed in to change notification settings - Fork 275
CBMC additional profiling info: Pointer dereference, points-to set metric #5475
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
15 commits
Select commit
Hold shift + click to select a range
a064697
Add parse option to display points-to set information for pointer der…
be9b086
Add show_points_to_sets to symex configuration to detect if CBMC pars…
bb6f89a
Add module to track points-to set information for pointer dereferenci…
4e7eb30
Regression test for --show-points-to-sets --json-ui
caa506a
Add module to track points-to set information for pointer dereferenci…
1a7dcea
Pass message handler to display points-to sets data
ad928a6
Add parse option to display points-to set information for pointer der…
cafc143
clang format regression test
e7fb35e
clang format regression test
92a5b75
Add parse option to display points-to set information for pointer der…
c1444c9
clang format regression test
4642ec7
Add parse option to display points-to set information for pointer der…
96c6ac8
Fix parse options handling for --show-points-to-sets
7c70957
fix #ifdef DEBUG in headers, keep iostream inside DEBUG tags
f179946
Add comment explaining the use if default messaget instance in goto_p…
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,9 @@ | ||
int main() | ||
{ | ||
unsigned int value; | ||
int *p = (int *)value; | ||
|
||
*p = *p + 1; | ||
assert(1); | ||
return 0; | ||
} |
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,9 @@ | ||
CORE | ||
main.c | ||
--show-points-to-sets | ||
^EXIT=1$ | ||
^SIGNAL=0$ | ||
-- | ||
-- | ||
To test output for --show-points-to-sets option that displays the size and contents of points-to sets in json format. | ||
xml-ui and plain output not supported. |
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,11 @@ | ||
CORE | ||
main.c | ||
--show-points-to-sets --json-ui | ||
activate-multi-line-match | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
\{\n\s*"Pointer": "main::1::p!0@1",\n\s*"PointsToSet": \[ "object_descriptor\(integer_address, unknown\)" \],\n\s*"PointsToSetSize": 1,\n\s*"RetainedValuesSet": \[ "object_descriptor\(integer_address, unknown\)" \],\n\s*"RetainedValuesSetSize": 1,\n\s*"Value": "byte_extract_little_endian\(__CPROVER_memory, pointer_offset\(main::1::p!0@1\), signedbv\[32\]\)"\n\s*\},\n\s*\{\n\s*"Pointer": "main::1::p!0@1",\n\s*"PointsToSet": \[ "object_descriptor\(integer_address, unknown\)" \],\n\s*"PointsToSetSize": 1,\n\s*"RetainedValuesSet": \[ "object_descriptor\(integer_address, unknown\)" \],\n\s*"RetainedValuesSetSize": 1,\n\s*"Value": "byte_extract_little_endian\(__CPROVER_memory, pointer_offset\(main::1::p!0@1\), signedbv\[32\]\)"\n\s*\} | ||
-- | ||
-- | ||
To test output for --show-points-to-sets option that displays the size and contents of points-to sets in json format. | ||
xml-ui and plain output not supported. |
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,9 @@ | ||
CORE | ||
main.c | ||
--show-points-to-sets --xml-ui | ||
^EXIT=1$ | ||
^SIGNAL=0$ | ||
-- | ||
-- | ||
To test output for --show-points-to-sets option that displays the size and contents of points-to sets in json format. | ||
xml-ui and plain output not supported. |
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
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 |
---|---|---|
|
@@ -13,7 +13,6 @@ Author: Daniel Kroening, [email protected] | |
|
||
#ifdef DEBUG | ||
#include <iostream> | ||
#include <util/format_expr.h> | ||
#endif | ||
|
||
#include <util/arith_tools.h> | ||
|
@@ -24,8 +23,10 @@ Author: Daniel Kroening, [email protected] | |
#include <util/cprover_prefix.h> | ||
#include <util/expr_iterator.h> | ||
#include <util/expr_util.h> | ||
#include <util/format_expr.h> | ||
#include <util/format_type.h> | ||
#include <util/fresh_symbol.h> | ||
#include <util/json_irep.h> | ||
#include <util/options.h> | ||
#include <util/pointer_offset_size.h> | ||
#include <util/pointer_predicates.h> | ||
|
@@ -60,7 +61,9 @@ static bool should_use_local_definition_for(const exprt &expr) | |
return false; | ||
} | ||
|
||
exprt value_set_dereferencet::dereference(const exprt &pointer) | ||
exprt value_set_dereferencet::dereference( | ||
const exprt &pointer, | ||
bool display_points_to_sets) | ||
{ | ||
if(pointer.type().id()!=ID_pointer) | ||
throw "dereference expected pointer type, but got "+ | ||
|
@@ -70,8 +73,9 @@ exprt value_set_dereferencet::dereference(const exprt &pointer) | |
if(pointer.id()==ID_if) | ||
{ | ||
const if_exprt &if_expr=to_if_expr(pointer); | ||
exprt true_case = dereference(if_expr.true_case()); | ||
exprt false_case = dereference(if_expr.false_case()); | ||
exprt true_case = dereference(if_expr.true_case(), display_points_to_sets); | ||
exprt false_case = | ||
dereference(if_expr.false_case(), display_points_to_sets); | ||
return if_exprt(if_expr.cond(), true_case, false_case); | ||
} | ||
else if(pointer.id() == ID_typecast) | ||
|
@@ -90,14 +94,26 @@ exprt value_set_dereferencet::dereference(const exprt &pointer) | |
const auto &if_expr = to_if_expr(*underlying); | ||
return if_exprt( | ||
if_expr.cond(), | ||
dereference(typecast_exprt(if_expr.true_case(), pointer.type())), | ||
dereference(typecast_exprt(if_expr.false_case(), pointer.type()))); | ||
dereference( | ||
typecast_exprt(if_expr.true_case(), pointer.type()), | ||
display_points_to_sets), | ||
dereference( | ||
typecast_exprt(if_expr.false_case(), pointer.type()), | ||
display_points_to_sets)); | ||
} | ||
} | ||
|
||
// type of the object | ||
const typet &type=pointer.type().subtype(); | ||
|
||
json_objectt json_result; | ||
if(display_points_to_sets) | ||
{ | ||
std::stringstream ss; | ||
ss << format(pointer); | ||
json_result["Pointer"] = json_stringt(ss.str()); | ||
} | ||
|
||
#ifdef DEBUG | ||
std::cout << "value_set_dereferencet::dereference pointer=" << format(pointer) | ||
<< '\n'; | ||
|
@@ -107,6 +123,22 @@ exprt value_set_dereferencet::dereference(const exprt &pointer) | |
const std::vector<exprt> points_to_set = | ||
dereference_callback.get_value_set(pointer); | ||
|
||
if(display_points_to_sets) | ||
{ | ||
json_result["PointsToSetSize"] = | ||
json_numbert(std::to_string(points_to_set.size())); | ||
|
||
json_arrayt points_to_set_json; | ||
for(auto p : points_to_set) | ||
{ | ||
std::stringstream ss; | ||
ss << format(p); | ||
points_to_set_json.push_back(json_stringt(ss.str())); | ||
} | ||
|
||
json_result["PointsToSet"] = points_to_set_json; | ||
} | ||
|
||
#ifdef DEBUG | ||
std::cout << "value_set_dereferencet::dereference points_to_set={"; | ||
for(auto p : points_to_set) | ||
|
@@ -135,6 +167,22 @@ exprt value_set_dereferencet::dereference(const exprt &pointer) | |
compare_against_pointer = fresh_binder.symbol_expr(); | ||
} | ||
|
||
if(display_points_to_sets) | ||
{ | ||
json_result["RetainedValuesSetSize"] = | ||
json_numbert(std::to_string(points_to_set.size())); | ||
|
||
json_arrayt retained_values_set_json; | ||
for(auto &value : retained_values) | ||
{ | ||
std::stringstream ss; | ||
ss << format(value); | ||
retained_values_set_json.push_back(json_stringt(ss.str())); | ||
} | ||
|
||
json_result["RetainedValuesSet"] = retained_values_set_json; | ||
} | ||
|
||
#ifdef DEBUG | ||
std::cout << "value_set_dereferencet::dereference retained_values={"; | ||
for(const auto &value : retained_values) | ||
|
@@ -224,6 +272,15 @@ exprt value_set_dereferencet::dereference(const exprt &pointer) | |
if(compare_against_pointer != pointer) | ||
value = let_exprt(to_symbol_expr(compare_against_pointer), pointer, value); | ||
|
||
if(display_points_to_sets) | ||
{ | ||
std::stringstream ss; | ||
ss << format(value); | ||
json_result["Value"] = json_stringt(ss.str()); | ||
|
||
log.status() << json_result; | ||
} | ||
|
||
#ifdef DEBUG | ||
std::cout << "value_set_derefencet::dereference value=" << format(value) | ||
<< '\n' | ||
|
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <unordered_set> | ||
|
||
#include <util/message.h> | ||
#include <util/std_expr.h> | ||
|
||
#include "dereference_callback.h" | ||
|
@@ -34,25 +35,29 @@ class value_set_dereferencet final | |
/// dereference failure | ||
/// \param _exclude_null_derefs: Ignore value-set entries that indicate a | ||
// given dereference may follow a null pointer | ||
/// \param _log: Messaget object for displaying points-to set | ||
value_set_dereferencet( | ||
const namespacet &_ns, | ||
symbol_tablet &_new_symbol_table, | ||
dereference_callbackt &_dereference_callback, | ||
const irep_idt _language_mode, | ||
bool _exclude_null_derefs): | ||
ns(_ns), | ||
new_symbol_table(_new_symbol_table), | ||
dereference_callback(_dereference_callback), | ||
language_mode(_language_mode), | ||
exclude_null_derefs(_exclude_null_derefs) | ||
bool _exclude_null_derefs, | ||
const messaget &_log) | ||
: ns(_ns), | ||
new_symbol_table(_new_symbol_table), | ||
dereference_callback(_dereference_callback), | ||
language_mode(_language_mode), | ||
exclude_null_derefs(_exclude_null_derefs), | ||
log(_log) | ||
{ } | ||
|
||
virtual ~value_set_dereferencet() { } | ||
|
||
/// Dereference the given pointer-expression. Any errors are | ||
/// reported to the callback method given in the constructor. | ||
/// \param pointer: A pointer-typed expression, to be dereferenced. | ||
exprt dereference(const exprt &pointer); | ||
/// \param display_points_to_sets: Display size and contents of points to sets | ||
exprt dereference(const exprt &pointer, bool display_points_to_sets = false); | ||
|
||
/// Return value for `build_reference_to`; see that method for documentation. | ||
class valuet | ||
|
@@ -105,6 +110,7 @@ class value_set_dereferencet final | |
/// Flag indicating whether `value_set_dereferencet::dereference` should | ||
/// disregard an apparent attempt to dereference NULL | ||
const bool exclude_null_derefs; | ||
const messaget &log; | ||
}; | ||
|
||
#endif // CPROVER_POINTER_ANALYSIS_VALUE_SET_DEREFERENCE_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.
❗Please don't remove the ifdef here.
iostream
must not be included outsideDEBUG
here.You can use
iosfwd
outsideDEBUG
- that's what you need here, as far as I can see.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.
Fixed.