Skip to content

API change: from_integer for negative naturals #3016

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

Merged
merged 1 commit into from
Sep 21, 2018
Merged
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
24 changes: 7 additions & 17 deletions src/util/arith_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,7 @@ constant_exprt from_integer(
}
else if(type_id==ID_natural)
{
if(int_value<0)
{
constant_exprt r;
r.make_nil();
return r;
}

PRECONDITION(int_value >= 0);
return constant_exprt(integer2string(int_value), type);
}
else if(type_id==ID_unsignedbv)
Expand Down Expand Up @@ -154,15 +148,16 @@ constant_exprt from_integer(
}
else if(type_id==ID_bool)
{
if(int_value==0)
PRECONDITION(int_value == 0 || int_value == 1);
if(int_value == 0)
return false_exprt();
else if(int_value==1)
else
return true_exprt();
}
else if(type_id==ID_pointer)
{
if(int_value==0)
return null_pointer_exprt(to_pointer_type(type));
PRECONDITION(int_value == 0);
return null_pointer_exprt(to_pointer_type(type));
}
else if(type_id==ID_c_bit_field)
{
Expand All @@ -182,13 +177,8 @@ constant_exprt from_integer(
ieee_float.from_integer(int_value);
return ieee_float.to_expr();
}

{
else
PRECONDITION(false);
constant_exprt r;
r.make_nil();
return r;
}
}

/// ceil(log2(size))
Expand Down