Skip to content

Commit 070da7b

Browse files
authored
Merge pull request #3038 from hannes-steffenhagen-diffblue/feature-invariant_cleanup-flattening-boolbv_equality
Feature invariant cleanup flattening/boolbv_equality.cpp
2 parents f7e224b + cbc78db commit 070da7b

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/solvers/flattening/boolbv_equality.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ literalt boolbvt::convert_equality(const equal_exprt &expr)
1919
{
2020
const bool is_base_type_eq =
2121
base_type_eq(expr.lhs().type(), expr.rhs().type(), ns);
22-
if(!is_base_type_eq)
23-
{
24-
const std::string error_msg =
25-
std::string("equality without matching types:\n") + "######### lhs: " +
26-
expr.lhs().pretty() + '\n' + "######### rhs: " + expr.rhs().pretty();
27-
throw bitvector_conversion_exceptiont(error_msg, expr);
28-
}
22+
DATA_INVARIANT_WITH_DIAGNOSTICS(
23+
is_base_type_eq,
24+
"types of expressions on each side of equality should match",
25+
irep_pretty_diagnosticst{expr.lhs()},
26+
irep_pretty_diagnosticst{expr.rhs()});
2927

3028
// see if it is an unbounded array
3129
if(is_unbounded_array(expr.lhs().type()))
@@ -41,24 +39,25 @@ literalt boolbvt::convert_equality(const equal_exprt &expr)
4139
return record_array_equality(expr);
4240
}
4341

44-
const bvt &bv0=convert_bv(expr.lhs());
45-
const bvt &bv1=convert_bv(expr.rhs());
42+
const bvt &lhs_bv = convert_bv(expr.lhs());
43+
const bvt &rhs_bv = convert_bv(expr.rhs());
4644

47-
DATA_INVARIANT(
48-
bv0.size() == bv1.size(),
49-
std::string("unexpected size mismatch on equality:\n") + "lhs: " +
50-
expr.lhs().pretty() + '\n' + "lhs size: " + std::to_string(bv0.size()) +
51-
'\n' + "rhs: " + expr.rhs().pretty() + '\n' +
52-
"rhs size: " + std::to_string(bv1.size()));
45+
DATA_INVARIANT_WITH_DIAGNOSTICS(
46+
lhs_bv.size() == rhs_bv.size(),
47+
"sizes of lhs and rhs bitvectors should match",
48+
irep_pretty_diagnosticst{expr.lhs()},
49+
"lhs size: " + std::to_string(lhs_bv.size()),
50+
irep_pretty_diagnosticst{expr.rhs()},
51+
"rhs size: " + std::to_string(rhs_bv.size()));
5352

54-
if(bv0.empty())
53+
if(lhs_bv.empty())
5554
{
5655
// An empty bit-vector comparison. It's not clear
5756
// what this is meant to say.
5857
return prop.new_variable();
5958
}
6059

61-
return bv_utils.equal(bv0, bv1);
60+
return bv_utils.equal(lhs_bv, rhs_bv);
6261
}
6362

6463
literalt boolbvt::convert_verilog_case_equality(
@@ -69,24 +68,25 @@ literalt boolbvt::convert_verilog_case_equality(
6968

7069
const bool is_base_type_eq =
7170
base_type_eq(expr.lhs().type(), expr.rhs().type(), ns);
72-
DATA_INVARIANT(
71+
DATA_INVARIANT_WITH_DIAGNOSTICS(
7372
is_base_type_eq,
74-
std::string("verilog_case_equality without matching types:\n") +
75-
"######### lhs: " + expr.lhs().pretty() + '\n' +
76-
"######### rhs: " + expr.rhs().pretty());
73+
"lhs and rhs types should match in verilog_case_equality",
74+
irep_pretty_diagnosticst{expr.lhs()},
75+
irep_pretty_diagnosticst{expr.rhs()});
7776

78-
const bvt &bv0=convert_bv(expr.lhs());
79-
const bvt &bv1=convert_bv(expr.rhs());
77+
const bvt &lhs_bv = convert_bv(expr.lhs());
78+
const bvt &rhs_bv = convert_bv(expr.rhs());
8079

81-
DATA_INVARIANT(
82-
bv0.size() == bv1.size(),
83-
std::string("unexpected size mismatch on verilog_case_equality:\n") +
84-
"lhs: " + expr.lhs().pretty() + '\n' + "lhs size: " +
85-
std::to_string(bv0.size()) + '\n' + "rhs: " + expr.rhs().pretty() + '\n' +
86-
"rhs size: " + std::to_string(bv1.size()));
80+
DATA_INVARIANT_WITH_DIAGNOSTICS(
81+
lhs_bv.size() == rhs_bv.size(),
82+
"bitvector arguments to verilog_case_equality should have the same size",
83+
irep_pretty_diagnosticst{expr.lhs()},
84+
"lhs size: " + std::to_string(lhs_bv.size()),
85+
irep_pretty_diagnosticst{expr.rhs()},
86+
"rhs size: " + std::to_string(rhs_bv.size()));
8787

8888
if(expr.id()==ID_verilog_case_inequality)
89-
return !bv_utils.equal(bv0, bv1);
89+
return !bv_utils.equal(lhs_bv, rhs_bv);
9090
else
91-
return bv_utils.equal(bv0, bv1);
91+
return bv_utils.equal(lhs_bv, rhs_bv);
9292
}

0 commit comments

Comments
 (0)