Skip to content

Use propt::lcnf when cnf_handled_well is true #7402

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

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions src/cprover/bv_pointers_wide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,30 @@
difference, element_size_bv, bv_utilst::representationt::SIGNED);
}

prop.l_set_to_true(prop.limplies(
prop.land(same_object_lit, prop.land(lhs_in_bounds, rhs_in_bounds)),
bv_utils.equal(difference, bv)));
if(prop.cnf_handled_well())
{
for(std::size_t i = 0; i < width; ++i)
{
prop.lcnf(
{!same_object_lit,
!lhs_in_bounds,
!rhs_in_bounds,
!difference[i],
bv[i]});
prop.lcnf(
{!same_object_lit,
!lhs_in_bounds,
!rhs_in_bounds,
difference[i],
!bv[i]});

Check warning on line 647 in src/cprover/bv_pointers_wide.cpp

View check run for this annotation

Codecov / codecov/patch

src/cprover/bv_pointers_wide.cpp#L636-L647

Added lines #L636 - L647 were not covered by tests
}
}
else
{
prop.l_set_to_true(prop.limplies(
prop.land(same_object_lit, prop.land(lhs_in_bounds, rhs_in_bounds)),
bv_utils.equal(difference, bv)));

Check warning on line 654 in src/cprover/bv_pointers_wide.cpp

View check run for this annotation

Codecov / codecov/patch

src/cprover/bv_pointers_wide.cpp#L652-L654

Added lines #L652 - L654 were not covered by tests
}
}

return bv;
Expand Down Expand Up @@ -892,7 +913,10 @@
if(!is_dynamic)
l2 = !l2;

prop.l_set_to_true(prop.limplies(l1, l2));
if(prop.cnf_handled_well())
prop.lcnf({!l1, l2});
else
prop.l_set_to_true(prop.limplies(l1, l2));

Check warning on line 919 in src/cprover/bv_pointers_wide.cpp

View check run for this annotation

Codecov / codecov/patch

src/cprover/bv_pointers_wide.cpp#L917-L919

Added lines #L917 - L919 were not covered by tests
}
}
else if(
Expand Down Expand Up @@ -933,7 +957,10 @@
literalt l1 = bv_utils.equal(bv, saved_bv);
literalt l2 = bv_utils.equal(postponed.bv, size_bv);

prop.l_set_to_true(prop.limplies(l1, l2));
if(prop.cnf_handled_well())
prop.lcnf({!l1, l2});

Check warning on line 961 in src/cprover/bv_pointers_wide.cpp

View check run for this annotation

Codecov / codecov/patch

src/cprover/bv_pointers_wide.cpp#L961

Added line #L961 was not covered by tests
else
prop.l_set_to_true(prop.limplies(l1, l2));

Check warning on line 963 in src/cprover/bv_pointers_wide.cpp

View check run for this annotation

Codecov / codecov/patch

src/cprover/bv_pointers_wide.cpp#L963

Added line #L963 was not covered by tests
}
}
else
Expand Down
16 changes: 13 additions & 3 deletions src/solvers/flattening/boolbv_bv_rel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,20 @@
{
literalt equal_lit = equality(lhs, rhs);

if(or_equal)
prop.l_set_to_true(prop.limplies(equal_lit, literal));
if(prop.cnf_handled_well())
{
if(or_equal)
prop.lcnf(!equal_lit, literal);
else
prop.lcnf(!equal_lit, !literal);
}
else
prop.l_set_to_true(prop.limplies(equal_lit, !literal));
{
if(or_equal)
prop.l_set_to_true(prop.limplies(equal_lit, literal));
else
prop.l_set_to_true(prop.limplies(equal_lit, !literal));

Check warning on line 88 in src/solvers/flattening/boolbv_bv_rel.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_bv_rel.cpp#L86-L88

Added lines #L86 - L88 were not covered by tests
}
}
}

Expand Down
29 changes: 26 additions & 3 deletions src/solvers/flattening/boolbv_byte_extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,32 @@
else
equal_bv[j]=const_literal(true);

prop.l_set_to_true(prop.limplies(
convert(equal_exprt(expr.offset(), from_integer(i, constant_type))),
prop.land(equal_bv)));
if(prop.cnf_handled_well())
{
literalt index_eq =
convert(equal_exprt(expr.offset(), from_integer(i, constant_type)));

for(std::size_t j = 0; j < width; j++)
{
if(offset + j >= op_bv.size())
break;

Check warning on line 153 in src/solvers/flattening/boolbv_byte_extract.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_byte_extract.cpp#L153

Added line #L153 was not covered by tests

prop.lcnf({!index_eq, !bv[j], op_bv[offset + j]});
prop.lcnf({!index_eq, bv[j], !op_bv[offset + j]});
}
}
else
{
for(std::size_t j = 0; j < width; j++)
if(offset + j < op_bv.size())
equal_bv[j] = prop.lequal(bv[j], op_bv[offset + j]);
else
equal_bv[j] = const_literal(true);

Check warning on line 165 in src/solvers/flattening/boolbv_byte_extract.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_byte_extract.cpp#L161-L165

Added lines #L161 - L165 were not covered by tests

prop.l_set_to_true(prop.limplies(
convert(equal_exprt(expr.offset(), from_integer(i, constant_type))),
prop.land(equal_bv)));

Check warning on line 169 in src/solvers/flattening/boolbv_byte_extract.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_byte_extract.cpp#L167-L169

Added lines #L167 - L169 were not covered by tests
}
}
}
else
Expand Down
6 changes: 4 additions & 2 deletions src/solvers/flattening/boolbv_case.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@
{
literalt value_literal=bv_utils.equal(bv, op);

prop.l_set_to_true(
prop.limplies(compare_literal, value_literal));
if(prop.cnf_handled_well())
prop.lcnf({!compare_literal, value_literal});

Check warning on line 72 in src/solvers/flattening/boolbv_case.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_case.cpp#L71-L72

Added lines #L71 - L72 were not covered by tests
else
prop.l_set_to_true(prop.limplies(compare_literal, value_literal));

Check warning on line 74 in src/solvers/flattening/boolbv_case.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_case.cpp#L74

Added line #L74 was not covered by tests
}

what=COMPARE;
Expand Down
16 changes: 13 additions & 3 deletions src/solvers/flattening/boolbv_cond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,19 @@
{
const bvt &op = convert_bv(operand, bv.size());

literalt value_literal=bv_utils.equal(bv, op);

prop.l_set_to_true(prop.limplies(cond_literal, value_literal));
if(prop.cnf_handled_well())

Check warning on line 48 in src/solvers/flattening/boolbv_cond.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_cond.cpp#L48

Added line #L48 was not covered by tests
{
for(std::size_t i = 0; i < bv.size(); ++i)

Check warning on line 50 in src/solvers/flattening/boolbv_cond.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_cond.cpp#L50

Added line #L50 was not covered by tests
{
prop.lcnf({!cond_literal, !bv[i], op[i]});
prop.lcnf({!cond_literal, bv[i], !op[i]});

Check warning on line 53 in src/solvers/flattening/boolbv_cond.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_cond.cpp#L52-L53

Added lines #L52 - L53 were not covered by tests
}
}
else
{
literalt value_literal = bv_utils.equal(bv, op);
prop.l_set_to_true(prop.limplies(cond_literal, value_literal));

Check warning on line 59 in src/solvers/flattening/boolbv_cond.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_cond.cpp#L58-L59

Added lines #L58 - L59 were not covered by tests
}
}

condition=!condition;
Expand Down
13 changes: 11 additions & 2 deletions src/solvers/flattening/boolbv_extractbit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,17 @@
for(std::size_t i = 0; i < src_bv.size(); i++)
{
equal_exprt equality(index_casted, from_integer(i, index_type));
literalt equal = prop.lequal(literal, src_bv[i]);
prop.l_set_to_true(prop.limplies(convert(equality), equal));
if(prop.cnf_handled_well())

Check warning on line 68 in src/solvers/flattening/boolbv_extractbit.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_extractbit.cpp#L68

Added line #L68 was not covered by tests
{
literalt index_eq = convert(equality);
prop.lcnf({!index_eq, !literal, src_bv[i]});
prop.lcnf({!index_eq, literal, !src_bv[i]});

Check warning on line 72 in src/solvers/flattening/boolbv_extractbit.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_extractbit.cpp#L70-L72

Added lines #L70 - L72 were not covered by tests
}
else
{
literalt equal = prop.lequal(literal, src_bv[i]);
prop.l_set_to_true(prop.limplies(convert(equality), equal));

Check warning on line 77 in src/solvers/flattening/boolbv_extractbit.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_extractbit.cpp#L76-L77

Added lines #L76 - L77 were not covered by tests
}
}

return literal;
Expand Down
47 changes: 38 additions & 9 deletions src/solvers/flattening/boolbv_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,18 @@
"past the array's end");

// Cache comparisons and equalities
prop.l_set_to_true(convert(implies_exprt(
equal_exprt(index, from_integer(i, index.type())),
equal_exprt(result, *it++))));
if(prop.cnf_handled_well())
{
prop.lcnf(
{!convert(equal_exprt(index, from_integer(i, index.type()))),
convert(equal_exprt(result, *it++))});
}
else
{
prop.l_set_to_true(convert(implies_exprt(
equal_exprt(index, from_integer(i, index.type())),
equal_exprt(result, *it++))));

Check warning on line 199 in src/solvers/flattening/boolbv_index.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_index.cpp#L197-L199

Added lines #L197 - L199 were not covered by tests
}
}

return bv;
Expand Down Expand Up @@ -229,13 +238,33 @@
{
mp_integer offset=i*width;

for(std::size_t j=0; j<width; j++)
equal_bv[j] = prop.lequal(
bv[j], array_bv[numeric_cast_v<std::size_t>(offset + j)]);
if(prop.cnf_handled_well())
{
literalt index_eq =
convert(equal_exprt(index, from_integer(i, index.type())));

for(std::size_t j = 0; j < width; j++)
{
prop.lcnf(
{!index_eq,
!bv[j],
array_bv[numeric_cast_v<std::size_t>(offset + j)]});
prop.lcnf(
{!index_eq,
bv[j],
!array_bv[numeric_cast_v<std::size_t>(offset + j)]});
}
}
else

Check warning on line 258 in src/solvers/flattening/boolbv_index.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_index.cpp#L258

Added line #L258 was not covered by tests
{
for(std::size_t j = 0; j < width; j++)
equal_bv[j] = prop.lequal(
bv[j], array_bv[numeric_cast_v<std::size_t>(offset + j)]);

Check warning on line 262 in src/solvers/flattening/boolbv_index.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_index.cpp#L261-L262

Added lines #L261 - L262 were not covered by tests

prop.l_set_to_true(prop.limplies(
convert(equal_exprt(index, from_integer(i, index.type()))),
prop.land(equal_bv)));
prop.l_set_to_true(prop.limplies(
convert(equal_exprt(index, from_integer(i, index.type()))),
prop.land(equal_bv)));

Check warning on line 266 in src/solvers/flattening/boolbv_index.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_index.cpp#L264-L266

Added lines #L264 - L266 were not covered by tests
}
}
}
else
Expand Down
37 changes: 30 additions & 7 deletions src/solvers/flattening/bv_pointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,20 @@
prop.lor(in_bounds, prop.land(lhs_in_bounds, rhs_in_bounds));
}

prop.l_set_to_true(prop.limplies(
prop.land(same_object_lit, in_bounds), bv_utils.equal(difference, bv)));
if(prop.cnf_handled_well())
{
for(std::size_t i = 0; i < width; ++i)
{
prop.lcnf({!same_object_lit, !in_bounds, !difference[i], bv[i]});
prop.lcnf({!same_object_lit, !in_bounds, difference[i], !bv[i]});
}
}
else

Check warning on line 708 in src/solvers/flattening/bv_pointers.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/bv_pointers.cpp#L708

Added line #L708 was not covered by tests
{
prop.l_set_to_true(prop.limplies(
prop.land(same_object_lit, in_bounds),
bv_utils.equal(difference, bv)));

Check warning on line 712 in src/solvers/flattening/bv_pointers.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/bv_pointers.cpp#L710-L712

Added lines #L710 - L712 were not covered by tests
}
}

return bv;
Expand Down Expand Up @@ -1071,10 +1083,18 @@
replace_expr(replacements, is_not_dyn);

PRECONDITION(postponed.bv.size() == 1);
prop.l_set_to_true(
prop.limplies(convert_bv(is_dyn)[0], postponed.bv.front()));
prop.l_set_to_true(
prop.limplies(convert_bv(is_not_dyn)[0], !postponed.bv.front()));
if(prop.cnf_handled_well())
{
prop.lcnf({!convert_bv(is_dyn)[0], postponed.bv.front()});
prop.lcnf({!convert_bv(is_not_dyn)[0], !postponed.bv.front()});
}
else

Check warning on line 1091 in src/solvers/flattening/bv_pointers.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/bv_pointers.cpp#L1091

Added line #L1091 was not covered by tests
{
prop.l_set_to_true(
prop.limplies(convert_bv(is_dyn)[0], postponed.bv.front()));
prop.l_set_to_true(
prop.limplies(convert_bv(is_not_dyn)[0], !postponed.bv.front()));

Check warning on line 1096 in src/solvers/flattening/bv_pointers.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/bv_pointers.cpp#L1093-L1096

Added lines #L1093 - L1096 were not covered by tests
}
}
else if(
const auto postponed_object_size =
Expand Down Expand Up @@ -1121,7 +1141,10 @@
#ifndef COMPACT_OBJECT_SIZE_EQ
literalt l2 = bv_utils.equal(postponed.bv, size_bv);

prop.l_set_to_true(prop.limplies(l1, l2));
if(prop.cnf_handled_well())
prop.lcnf({!l1, l2});
else
prop.l_set_to_true(prop.limplies(l1, l2));
#else
for(std::size_t i = 0; i < postponed.bv.size(); ++i)
{
Expand Down
Loading
Loading