-
Notifications
You must be signed in to change notification settings - Fork 0
Replace asserts and throws under goto-symex #6
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
Changes from 4 commits
16d03d7
526945e
112bd5b
c7fb551
b43902e
2d913c4
77b43ea
46aeea4
f2a7a37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,7 +92,7 @@ exprt build_full_lhs_rec( | |
id==ID_byte_extract_big_endian) | ||
{ | ||
exprt tmp=src_original; | ||
assert(tmp.operands().size()==2); | ||
PRECONDITION(tmp.operands().size() == 2); | ||
tmp.op0()=build_full_lhs_rec(prop_conv, ns, tmp.op0(), src_ssa.op0()); | ||
|
||
// re-write into big case-split | ||
|
@@ -222,7 +222,7 @@ void build_goto_trace( | |
else if(it->is_atomic_end() && current_time<0) | ||
current_time*=-1; | ||
|
||
assert(current_time>=0); | ||
INVARIANT(current_time>=0, "time keeping inconsistency"); | ||
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. Again, isn't this a DATA_INVARIANT? 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. No. This is what the
To my understanding this is to assert properties of fundamental data structures representing the program under analysis. In this case 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. Seems reasonable, thanks. |
||
// move any steps gathered in an atomic section | ||
|
||
if(time_before<0) | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,8 +51,7 @@ void goto_symex_statet::level0t::operator()( | |
|
||
const symbolt *s; | ||
const bool found_l0 = !ns.lookup(obj_identifier, s); | ||
DATA_INVARIANT( | ||
found_l0, "level0: failed to find " + id2string(obj_identifier)); | ||
INVARIANT(found_l0, "level0: failed to find " + id2string(obj_identifier)); | ||
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. Nice catch, this indeed doesn't seem to meet the definition of |
||
|
||
// don't rename shared variables or functions | ||
if(s->type.id()==ID_code || | ||
|
@@ -187,8 +186,7 @@ bool goto_symex_statet::constant_propagation_reference(const exprt &expr) const | |
} | ||
else if(expr.id()==ID_member) | ||
{ | ||
if(expr.operands().size()!=1) | ||
throw "member expects one operand"; | ||
PRECONDITION(expr.operands().size() == 1); | ||
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. Surely DATA_INVARIANT? 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. By definition this falls between multiple categories of the invariant checks (it falls both under But I can certainly change it to the |
||
|
||
return constant_propagation_reference(expr.op0()); | ||
} | ||
|
@@ -495,12 +493,10 @@ void goto_symex_statet::rename( | |
} | ||
else if(expr.id()==ID_address_of) | ||
{ | ||
PRECONDITION(expr.type().id() == ID_pointer); | ||
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 should probably be the first thing that's being checked in this block? 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. Isn't this DATA_INVARIANT? 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. Same thing as above really, but I can change it to make it clearer. |
||
DATA_INVARIANT( | ||
expr.operands().size() == 1, "address_of should have a single operand"); | ||
expr.operands().size() == 1, "address_of should have a single operand"); | ||
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. Unnecessary (and incorrect) indentation change. |
||
rename_address(expr.op0(), ns, level); | ||
DATA_INVARIANT( | ||
expr.type().id() == ID_pointer, | ||
"type of address_of should be ID_pointer"); | ||
expr.type().subtype()=expr.op0().type(); | ||
} | ||
else | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,8 +36,8 @@ bool memory_model_sct::program_order_is_relaxed( | |
partial_order_concurrencyt::event_it e1, | ||
partial_order_concurrencyt::event_it e2) const | ||
{ | ||
assert(e1->is_shared_read() || e1->is_shared_write()); | ||
assert(e2->is_shared_read() || e2->is_shared_write()); | ||
PRECONDITION(e1->is_shared_read() || e1->is_shared_write()); | ||
PRECONDITION(e2->is_shared_read() || e2->is_shared_write()); | ||
|
||
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. Not a comment on this change, but "yuck" to this function... it's basically just an assertion in it's own right, or it's using preconditions as control flow/error handling. Might be worth checking where this function is used, because if its used in anyway that doesn't just use it as an assertion, that use-site needs looking at/adjusting. 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. It seems that this method is an implementation of a virtual method in the base class. For the particular memory model (sequential consistency), just returning |
||
return false; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,20 +76,22 @@ bool postconditiont::is_used_address_of( | |
} | ||
else if(expr.id()==ID_index) | ||
{ | ||
assert(expr.operands().size()==2); | ||
|
||
DATA_INVARIANT( | ||
expr.operands().size() == 2, "index expression should have two operands"); | ||
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. Nit: Indentation is wrong? |
||
return | ||
is_used_address_of(expr.op0(), identifier) || | ||
is_used(expr.op1(), identifier); | ||
} | ||
else if(expr.id()==ID_member) | ||
{ | ||
assert(expr.operands().size()==1); | ||
DATA_INVARIANT( | ||
expr.operands().size() == 1, "member expression should only have one operand"); | ||
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. Nit: Indentation is wrong? |
||
return is_used_address_of(expr.op0(), identifier); | ||
} | ||
else if(expr.id()==ID_dereference) | ||
{ | ||
assert(expr.operands().size()==1); | ||
DATA_INVARIANT( | ||
expr.operands().size() == 1, "dereference expression should only have one operand"); | ||
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. Nit: Indentation again. |
||
return is_used(expr.op0(), identifier); | ||
} | ||
|
||
|
@@ -155,7 +157,9 @@ bool postconditiont::is_used( | |
if(expr.id()==ID_address_of) | ||
{ | ||
// only do index! | ||
assert(expr.operands().size()==1); | ||
DATA_INVARIANT( | ||
expr.operands().size() == 1, | ||
"address_of expression expected to have one operand at this point"); | ||
return is_used_address_of(expr.op0(), identifier); | ||
} | ||
else if(expr.id()==ID_symbol && | ||
|
@@ -169,7 +173,9 @@ bool postconditiont::is_used( | |
} | ||
else if(expr.id()==ID_dereference) | ||
{ | ||
assert(expr.operands().size()==1); | ||
DATA_INVARIANT( | ||
expr.operands().size() == 1, | ||
"dereference expression expected to have one operand"); | ||
|
||
// aliasing may happen here | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,18 +78,21 @@ void preconditiont::compute_address_of(exprt &dest) | |
} | ||
else if(dest.id()==ID_index) | ||
{ | ||
assert(dest.operands().size()==2); | ||
DATA_INVARIANT( | ||
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. Indentation looks wrong in all the changes in this file |
||
dest.operands().size() == 2, "index expression expected to have two operands"); | ||
compute_address_of(dest.op0()); | ||
compute(dest.op1()); | ||
} | ||
else if(dest.id()==ID_member) | ||
{ | ||
assert(dest.operands().size()==1); | ||
DATA_INVARIANT( | ||
dest.operands().size() == 1, "member expression expected to have one operand"); | ||
compute_address_of(dest.op0()); | ||
} | ||
else if(dest.id()==ID_dereference) | ||
{ | ||
assert(dest.operands().size()==1); | ||
DATA_INVARIANT( | ||
dest.operands().size() == 1, "dereference expression expected to have 1 operand"); | ||
compute(dest.op0()); | ||
} | ||
} | ||
|
@@ -104,12 +107,16 @@ void preconditiont::compute_rec(exprt &dest) | |
if(dest.id()==ID_address_of) | ||
{ | ||
// only do index! | ||
assert(dest.operands().size()==1); | ||
DATA_INVARIANT( | ||
dest.operands().size() == 1, | ||
"address_of expression expected to have one operand at this point"); | ||
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. "at this point" isn't needed - keep them tight. |
||
compute_address_of(dest.op0()); | ||
} | ||
else if(dest.id()==ID_dereference) | ||
{ | ||
assert(dest.operands().size()==1); | ||
DATA_INVARIANT( | ||
dest.operands().size() == 1, | ||
"dereference expression expected to have one operand at this point"); | ||
|
||
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. "at this point" isn't needed |
||
const irep_idt &lhs_identifier=SSA_step.ssa_lhs.get_object_name(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,7 +112,7 @@ void symex_slicet::slice(symex_target_equationt::SSA_stept &SSA_step) | |
void symex_slicet::slice_assignment( | ||
symex_target_equationt::SSA_stept &SSA_step) | ||
{ | ||
assert(SSA_step.ssa_lhs.id()==ID_symbol); | ||
PRECONDITION(SSA_step.ssa_lhs.id() == ID_symbol); | ||
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. Is this a DATA_INVARIANT? 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. No, this falls very clearly under the |
||
const irep_idt &id=SSA_step.ssa_lhs.get_identifier(); | ||
|
||
if(depends.find(id)==depends.end()) | ||
|
@@ -127,7 +127,7 @@ void symex_slicet::slice_assignment( | |
void symex_slicet::slice_decl( | ||
symex_target_equationt::SSA_stept &SSA_step) | ||
{ | ||
assert(SSA_step.ssa_lhs.id()==ID_symbol); | ||
PRECONDITION(SSA_step.ssa_lhs.id() == ID_symbol); | ||
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. DATA_INVARIANT ? 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. Again, no, because this makes an assertion about the function arguments as the first thing the function does. |
||
const irep_idt &id=SSA_step.ssa_lhs.get_identifier(); | ||
|
||
if(depends.find(id)==depends.end()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,13 @@ void symex_slice_by_tracet::slice_by_trace( | |
{ | ||
exprt g_copy(*i); | ||
|
||
INVARIANT( | ||
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. I'm actually a bit ambivalent about this. Arguably could be a precondition, but since we're not using function args directly we should probably keep this an invariant. 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. I'd almost be tempted to say its a DATA_INVARIANT |
||
g_copy.id() == ID_symbol || | ||
g_copy.id() == ID_not || | ||
g_copy.id() == ID_and || | ||
g_copy.id() == ID_constant, | ||
"guards should only be and, symbol, constant, or `not'"); | ||
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. Previously, this was throwing an exception for 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. @johnnonweiler No it wasn't (https://github.com/diffblue/cbmc/blob/develop/src/goto-symex/slice_by_trace.cpp#L95). What that did is that it checked if the expression's type is This 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. Sorry @NlightNFotis - I got confused by GitHub hiding a couple of lines in the diff! |
||
|
||
if(g_copy.id()==ID_symbol || g_copy.id() == ID_not) | ||
{ | ||
g_copy.make_not(); | ||
|
@@ -92,10 +99,6 @@ void symex_slice_by_tracet::slice_by_trace( | |
simplify(copy_last, ns); | ||
implications.insert(copy_last); | ||
} | ||
else if(!(g_copy.id()==ID_constant)) | ||
{ | ||
throw "guards should only be and, symbol, constant, or `not'"; | ||
} | ||
} | ||
|
||
slice_SSA_steps(equation, implications); // Slice based on implications | ||
|
@@ -219,9 +222,9 @@ void symex_slice_by_tracet::parse_events(std::string read_line) | |
const std::string::size_type vnext=read_line.find(",", vidx); | ||
std::string event=read_line.substr(vidx, vnext - vidx); | ||
eis.insert(event); | ||
if((!alphabet.empty()) && | ||
((alphabet.count(event)!=0)!=alphabet_parity)) | ||
throw "trace uses symbol not in alphabet: "+event; | ||
PRECONDITION(!alphabet.empty()); | ||
INVARIANT((alphabet.count(event) != 0) == alphabet_parity, | ||
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. DATA_INVARIANT ? 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. No, this is not a data structure that represents the program under analysis to my understanding (i.e. not an |
||
"trace uses symbol not in alphabet: " + event); | ||
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. Description should describe what is being asserted.... "trace symbol must be in alphabet" |
||
if(vnext==std::string::npos) | ||
break; | ||
vidx=vnext; | ||
|
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.
Minor nit: Why not move the PRECONDITION to be the first line in the block?
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.
Should this be a DATA_INVARIANT ?