Skip to content

Handle infinity in the back-end and in the simplifier #6914

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
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions regression/cbmc/infinity1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int A[__CPROVER_constant_infinity_uint];

int main()
{
__CPROVER_assert(__CPROVER_OBJECT_SIZE(A) > 0, "infinity is positive");
}
8 changes: 8 additions & 0 deletions regression/cbmc/infinity1/no-simplify.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--no-simplify
^VERIFICATION SUCCESSFUL$
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
8 changes: 8 additions & 0 deletions regression/cbmc/infinity1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c

^VERIFICATION SUCCESSFUL$
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
10 changes: 9 additions & 1 deletion src/solvers/flattening/bv_pointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,9 +941,17 @@ void bv_pointerst::do_postponed(
if(!size_expr.has_value())
continue;

const exprt object_size = typecast_exprt::conditional_cast(
exprt object_size = typecast_exprt::conditional_cast(
size_expr.value(), postponed_object_size->type());

if(
size_expr->id() == ID_infinity &&
can_cast_type<integer_bitvector_typet>(object_size.type()))
{
object_size = to_integer_bitvector_type(postponed_object_size->type())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the actual size of infinity still bounded by the maximum offset size in the current pointer encoding?

.largest_expr();
}

// only compare object part
pointer_typet pt = pointer_type(expr.type());
bvt bv = object_literals(encode(number, pt), type);
Expand Down
12 changes: 12 additions & 0 deletions src/solvers/smt2/smt2_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ void smt2_convt::define_object_size(
{
const typet &type = o.type();
auto size_expr = size_of_expr(type, ns);
if(
size_expr.has_value() && size_expr->id() == ID_infinity &&
can_cast_type<integer_bitvector_typet>(expr.type()))
{
size_expr = to_integer_bitvector_type(expr.type()).largest_expr();
}
const auto object_size =
numeric_cast<mp_integer>(size_expr.value_or(nil_exprt()));

Expand Down Expand Up @@ -4962,6 +4968,12 @@ void smt2_convt::find_symbols(const exprt &expr)
convert_type(object_size->type());
out << ")"
<< "\n";
out << "(declare-fun |op_" << id << "| () ";
convert_type(object_size->op().type());
out << ")\n";
out << "(assert (= |op_" << id << "| ";
convert_expr(object_size->op());
out << "))\n";

object_sizes[*object_size] = id;
}
Expand Down
2 changes: 2 additions & 0 deletions src/util/pointer_offset_size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ optionalt<exprt> size_of_expr(const typet &type, const namespacet &ns)

if(size.is_nil())
return {};
else if(size.id() == ID_infinity)
return infinity_exprt{sub.value().type()};

const auto size_casted =
typecast_exprt::conditional_cast(size, sub.value().type());
Expand Down
31 changes: 31 additions & 0 deletions src/util/simplify_expr_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,29 @@ simplify_exprt::simplify_inequality(const binary_relation_exprt &expr)
return simplify_inequality_pointer_object(expr);
}

if(tmp0.id() == ID_infinity)
{
if(expr.id() == ID_ge)
return true_exprt{};
else if(expr.id() == ID_gt)
return changed(simplify_inequality(notequal_exprt{tmp0, tmp1}));
else if(expr.id() == ID_le)
return changed(simplify_inequality(equal_exprt{tmp0, tmp1}));
else if(expr.id() == ID_lt)
return false_exprt{};
}
else if(tmp1.id() == ID_infinity)
{
if(expr.id() == ID_ge)
return changed(simplify_inequality(equal_exprt{tmp0, tmp1}));
else if(expr.id() == ID_gt)
return false_exprt{};
else if(expr.id() == ID_le)
return true_exprt{};
else if(expr.id() == ID_lt)
return changed(simplify_inequality(notequal_exprt{tmp0, tmp1}));
}

if(tmp0.type().id()==ID_c_enum_tag)
tmp0.type()=ns.follow_tag(to_c_enum_tag_type(tmp0.type()));

Expand Down Expand Up @@ -1568,6 +1591,14 @@ simplify_exprt::resultt<> simplify_exprt::simplify_inequality_rhs_is_constant(
return changed(simplify_if(if_expr));
}

if(expr.op0().id() == ID_infinity)
{
if(expr.id() == ID_equal)
return false_exprt{};
else if(expr.id() == ID_notequal)
return true_exprt{};
}

// do we deal with pointers?
if(expr.op1().type().id()==ID_pointer)
{
Expand Down