-
Notifications
You must be signed in to change notification settings - Fork 274
Value-set dereference: use cond_exprt to avoid quadratic guards #4555
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
Closed
smowton
wants to merge
12
commits into
diffblue:develop
from
smowton:smowton/feature/value-set-deref-cond-expr
Closed
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
93e4622
Add exclusive flag to cond_exprt
smowton 1a553e0
Add accessors to cond_exprt
smowton e860099
value-set-dereference: return a cond_exprt
smowton ae870f1
goto-symex: handle cond_exprt on the LHS
smowton f57ebf2
Use lift-if more consistently
smowton 739e11d
Add lift_cond
smowton 3629f2a
Simplify cond_exprt
smowton 3645437
Add missing case to bv_pointerst
smowton 59145f1
Value-set: handle cond_exprt on the RHS
smowton b56063b
Lower cond_expr on the RHS
smowton 2fc837c
process_array_expr: handle ID_cond
smowton 2e48edd
Add cases handling cond_exprt wherever symex or value-set currently h…
smowton 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 |
---|---|---|
|
@@ -107,12 +107,12 @@ exprt value_set_dereferencet::dereference(const exprt &pointer) | |
may_fail=true; | ||
} | ||
|
||
exprt failure_value; | ||
|
||
if(may_fail) | ||
{ | ||
// first see if we have a "failed object" for this pointer | ||
|
||
exprt failure_value; | ||
|
||
if( | ||
const symbolt *failed_symbol = | ||
dereference_callback.get_or_create_failed_symbol(pointer)) | ||
|
@@ -138,36 +138,61 @@ exprt value_set_dereferencet::dereference(const exprt &pointer) | |
failure_value=symbol.symbol_expr(); | ||
failure_value.set(ID_C_invalid_object, true); | ||
} | ||
|
||
valuet value; | ||
value.value=failure_value; | ||
value.pointer_guard=true_exprt(); | ||
values.push_front(value); | ||
} | ||
|
||
// now build big case split, but we only do "good" objects | ||
|
||
exprt value=nil_exprt(); | ||
|
||
for(std::list<valuet>::const_iterator | ||
it=values.begin(); | ||
it!=values.end(); | ||
it++) | ||
optionalt<exprt> value_without_condition; | ||
cond_exprt cond({}, type, true); | ||
for(const auto &alias_value : values) | ||
{ | ||
if(it->value.is_not_nil()) | ||
if(alias_value.value.is_not_nil()) | ||
{ | ||
if(value.is_nil()) // first? | ||
value=it->value; | ||
if(alias_value.pointer_guard.is_false()) | ||
{ | ||
INVARIANT( | ||
!value_without_condition.has_value(), | ||
"can't discriminate between two different catch-all aliases"); | ||
value_without_condition = alias_value.value; | ||
} | ||
else | ||
value=if_exprt(it->pointer_guard, it->value, value); | ||
{ | ||
cond.add_case(alias_value.pointer_guard, alias_value.value); | ||
INVARIANT( | ||
alias_value.value.type() == type, | ||
"deref value types should match the pointer being derefd"); | ||
} | ||
} | ||
} | ||
|
||
#if 0 | ||
std::cout << "R: " << format(value) << "\n\n"; | ||
#endif | ||
// I'd like to put an invariant here that values without a pointer guard, such | ||
// as integer_address, cannot co-occur with failed objects, but this isn't the | ||
// case. There's no way to write a GOTO condition to discriminate between the | ||
// two however, so purely by historical accident, the failed object takes | ||
// precedence: | ||
|
||
if(may_fail || value_without_condition.has_value()) | ||
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. Can't we just combine |
||
{ | ||
// The cases must be disjoint, so add | ||
// "!(p == &o1 || p == &o2 || p == &o3 || ...) => failure-value" | ||
exprt::operandst other_case_conditions; | ||
for(std::size_t i = 0; i < cond.get_n_cases(); ++i) | ||
other_case_conditions.push_back(cond.condition(i)); | ||
cond.add_case( | ||
not_exprt(disjunction(other_case_conditions)), | ||
may_fail ? failure_value : *value_without_condition); | ||
} | ||
|
||
return value; | ||
#if 0 | ||
std::cout << "R: " << format(cond) << "\n\n"; | ||
#endif | ||
|
||
if(cond.get_n_cases() == 0) | ||
return nil_exprt(); | ||
else if(cond.get_n_cases() == 1) | ||
return cond.value(0); | ||
else | ||
return std::move(cond); | ||
} | ||
|
||
/// Check if the two types have matching number of ID_pointer levels, with | ||
|
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.
I find it too non-trivial to check that
failure_value
is never used uninitialised. See comment below.