-
Notifications
You must be signed in to change notification settings - Fork 274
Error handling cleanup in solvers/flattening 3 #2933
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 1 commit
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 |
---|---|---|
|
@@ -12,6 +12,8 @@ Author: Daniel Kroening, [email protected] | |
|
||
bvt boolbvt::convert_mult(const exprt &expr) | ||
{ | ||
PRECONDITION(expr.id() == ID_mult || expr.id() == "no-overflow-mult"); | ||
|
||
std::size_t width=boolbv_width(expr.type()); | ||
|
||
if(width==0) | ||
|
@@ -21,39 +23,34 @@ bvt boolbvt::convert_mult(const exprt &expr) | |
bv.resize(width); | ||
|
||
const exprt::operandst &operands=expr.operands(); | ||
if(operands.empty()) | ||
throw "mult without operands"; | ||
DATA_INVARIANT(!operands.empty(), "multiplication must have operands"); | ||
|
||
const exprt &op0=expr.op0(); | ||
|
||
bool no_overflow=expr.id()=="no-overflow-mult"; | ||
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 can be removed then too. |
||
|
||
DATA_INVARIANT( | ||
op0.type() == expr.type(), | ||
"multiplication operands should have same type as expression"); | ||
|
||
if(expr.type().id()==ID_fixedbv) | ||
{ | ||
if(op0.type()!=expr.type()) | ||
throw "multiplication with mixed types"; | ||
|
||
bv=convert_bv(op0); | ||
|
||
if(bv.size()!=width) | ||
throw "convert_mult: unexpected operand width"; | ||
bv = convert_bv(op0, width); | ||
|
||
std::size_t fraction_bits= | ||
to_fixedbv_type(expr.type()).get_fraction_bits(); | ||
|
||
for(exprt::operandst::const_iterator it=operands.begin()+1; | ||
it!=operands.end(); it++) | ||
{ | ||
if(it->type()!=expr.type()) | ||
throw "multiplication with mixed types"; | ||
DATA_INVARIANT( | ||
it->type() == expr.type(), | ||
"multiplication operands should have same type as expression"); | ||
|
||
// do a sign extension by fraction_bits bits | ||
bv=bv_utils.sign_extension(bv, bv.size()+fraction_bits); | ||
|
||
bvt op=convert_bv(*it); | ||
|
||
if(op.size()!=width) | ||
throw "convert_mult: unexpected operand width"; | ||
bvt op = convert_bv(*it, width); | ||
|
||
op=bv_utils.sign_extension(op, bv.size()); | ||
|
||
|
@@ -68,28 +65,20 @@ bvt boolbvt::convert_mult(const exprt &expr) | |
else if(expr.type().id()==ID_unsignedbv || | ||
expr.type().id()==ID_signedbv) | ||
{ | ||
if(op0.type()!=expr.type()) | ||
throw "multiplication with mixed types"; | ||
|
||
bv_utilst::representationt rep= | ||
expr.type().id()==ID_signedbv?bv_utilst::representationt::SIGNED: | ||
bv_utilst::representationt::UNSIGNED; | ||
|
||
bv=convert_bv(op0); | ||
|
||
if(bv.size()!=width) | ||
throw "convert_mult: unexpected operand width"; | ||
bv = convert_bv(op0, width); | ||
|
||
for(exprt::operandst::const_iterator it=operands.begin()+1; | ||
it!=operands.end(); it++) | ||
{ | ||
if(it->type()!=expr.type()) | ||
throw "multiplication with mixed types"; | ||
|
||
const bvt &op=convert_bv(*it); | ||
DATA_INVARIANT( | ||
it->type() == expr.type(), | ||
"multiplication operands should have same type as expression"); | ||
|
||
if(op.size()!=width) | ||
throw "convert_mult: unexpected operand width"; | ||
const bvt &op = convert_bv(*it, width); | ||
|
||
if(no_overflow) | ||
bv=bv_utils.multiplier_no_overflow(bv, op, rep); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,7 @@ Author: Daniel Kroening, [email protected] | |
bvt boolbvt::convert_not(const not_exprt &expr) | ||
{ | ||
const bvt &op_bv=convert_bv(expr.op()); | ||
|
||
if(op_bv.empty()) | ||
throw "not operator takes one non-empty operand"; | ||
CHECK_RETURN(!op_bv.empty()); | ||
|
||
const typet &op_type=expr.op().type(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ Author: Daniel Kroening, [email protected] | |
|
||
literalt boolbvt::convert_onehot(const unary_exprt &expr) | ||
{ | ||
PRECONDITION(expr.id() == ID_onehot || expr.id() == ID_onehot0); | ||
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. Are those expressions used anywhere? The IDs are not assigned anywhere. 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. They are used in ebmc. 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. Raised an issue for those as well: #3040 |
||
|
||
bvt op=convert_bv(expr.op()); | ||
|
||
literalt one_seen=const_literal(false); | ||
|
@@ -25,8 +27,12 @@ literalt boolbvt::convert_onehot(const unary_exprt &expr) | |
|
||
if(expr.id()==ID_onehot) | ||
return prop.land(one_seen, !more_than_one_seen); | ||
else if(expr.id()==ID_onehot0) | ||
return !more_than_one_seen; | ||
else | ||
throw "unexpected onehot expression"; | ||
{ | ||
INVARIANT( | ||
expr.id() == ID_onehot0, | ||
"should be a onehot0 expression as other onehot expression kind has been " | ||
"handled in other branch"); | ||
return !more_than_one_seen; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,9 @@ literalt boolbvt::convert_overflow(const exprt &expr) | |
if(expr.id()==ID_overflow_plus || | ||
expr.id()==ID_overflow_minus) | ||
{ | ||
if(operands.size()!=2) | ||
throw "operator "+expr.id_string()+" takes two operands"; | ||
DATA_INVARIANT( | ||
operands.size() == 2, | ||
"expression " + expr.id_string() + " should have two operands"); | ||
|
||
const bvt &bv0=convert_bv(operands[0]); | ||
const bvt &bv1=convert_bv(operands[1]); | ||
|
@@ -38,27 +39,25 @@ literalt boolbvt::convert_overflow(const exprt &expr) | |
} | ||
else if(expr.id()==ID_overflow_mult) | ||
{ | ||
if(operands.size()!=2) | ||
throw "operator "+expr.id_string()+" takes two operands"; | ||
DATA_INVARIANT( | ||
operands.size() == 2, | ||
"overflow_mult expression should have two operands"); | ||
|
||
if(operands[0].type().id()!=ID_unsignedbv && | ||
operands[0].type().id()!=ID_signedbv) | ||
return SUB::convert_rest(expr); | ||
|
||
bvt bv0=convert_bv(operands[0]); | ||
bvt bv1=convert_bv(operands[1]); | ||
|
||
if(bv0.size()!=bv1.size()) | ||
throw "operand size mismatch on overflow-*"; | ||
bvt bv1 = convert_bv(operands[1], bv0.size()); | ||
|
||
bv_utilst::representationt rep= | ||
operands[0].type().id()==ID_signedbv?bv_utilst::representationt::SIGNED: | ||
bv_utilst::representationt::UNSIGNED; | ||
|
||
if(operands[0].type()!=operands[1].type()) | ||
throw "operand type mismatch on overflow-*"; | ||
DATA_INVARIANT( | ||
operands[0].type() == operands[1].type(), | ||
"operands of overflow_mult expression shall have same type"); | ||
|
||
DATA_INVARIANT(bv0.size()==bv1.size(), "operands size mismatch"); | ||
std::size_t old_size=bv0.size(); | ||
std::size_t new_size=old_size*2; | ||
|
||
|
@@ -97,8 +96,8 @@ literalt boolbvt::convert_overflow(const exprt &expr) | |
} | ||
else if(expr.id() == ID_overflow_shl) | ||
{ | ||
if(operands.size() != 2) | ||
throw "operator " + expr.id_string() + " takes two operands"; | ||
DATA_INVARIANT( | ||
operands.size() == 2, "overflow_shl expression should have two operands"); | ||
|
||
const bvt &bv0=convert_bv(operands[0]); | ||
const bvt &bv1=convert_bv(operands[1]); | ||
|
@@ -163,8 +162,9 @@ literalt boolbvt::convert_overflow(const exprt &expr) | |
} | ||
else if(expr.id()==ID_overflow_unary_minus) | ||
{ | ||
if(operands.size()!=1) | ||
throw "operator "+expr.id_string()+" takes one operand"; | ||
DATA_INVARIANT( | ||
operands.size() == 1, | ||
"overflow_unary_minus expression should have one operand"); | ||
|
||
const bvt &bv=convert_bv(operands[0]); | ||
|
||
|
@@ -173,18 +173,19 @@ literalt boolbvt::convert_overflow(const exprt &expr) | |
else if(has_prefix(expr.id_string(), "overflow-typecast-")) | ||
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 |
||
{ | ||
std::size_t bits=unsafe_string2unsigned(id2string(expr.id()).substr(18)); | ||
INVARIANT(bits != 0, ""); | ||
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. Missing message |
||
|
||
const exprt::operandst &operands=expr.operands(); | ||
|
||
if(operands.size()!=1) | ||
throw "operator "+expr.id_string()+" takes one operand"; | ||
DATA_INVARIANT( | ||
operands.size() == 1, | ||
"expression " + expr.id_string() + " should have one operand"); | ||
|
||
const exprt &op=operands[0]; | ||
|
||
const bvt &bv=convert_bv(op); | ||
|
||
if(bits>=bv.size() || bits==0) | ||
throw "overflow-typecast got wrong number of bits"; | ||
INVARIANT(bits < bv.size(), ""); | ||
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. Missing message |
||
|
||
// signed or unsigned? | ||
if(op.type().id()==ID_signedbv) | ||
|
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.
Is
"no-overflow-mult"
still used? It does not seem to be assigned anywhere. If not, we can remove it and makeconvert_mult
take amult_exprt
instead.