Skip to content

remove instances of to_unsigned_integer #3065

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 3 commits into from
Oct 22, 2018
Merged
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
8 changes: 2 additions & 6 deletions jbmc/src/java_bytecode/java_bytecode_convert_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,9 +1069,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
{
PRECONDITION(!i_it->args.empty());

unsigned target;
bool ret=to_unsigned_integer(to_constant_expr(i_it->args[0]), target);
DATA_INVARIANT(!ret, "target expected to be unsigned integer");
auto target = numeric_cast_v<unsigned>(to_constant_expr(i_it->args[0]));
targets.insert(target);

a_entry.first->second.successors.push_back(target);
Expand All @@ -1094,9 +1092,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
{
if(is_label)
{
unsigned target;
bool ret=to_unsigned_integer(to_constant_expr(arg), target);
DATA_INVARIANT(!ret, "target expected to be unsigned integer");
auto target = numeric_cast_v<unsigned>(to_constant_expr(arg));
targets.insert(target);
a_entry.first->second.successors.push_back(target);
}
Expand Down
3 changes: 1 addition & 2 deletions jbmc/src/java_bytecode/java_local_variable_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ static bool is_store_to_slot(
{
// Store with an argument:
const auto &arg=inst.args[0];
bool ret=to_unsigned_integer(to_constant_expr(arg), storeslotidx);
CHECK_RETURN(!ret);
storeslotidx = numeric_cast_v<unsigned>(to_constant_expr(arg));
}
else
{
Expand Down
21 changes: 9 additions & 12 deletions src/solvers/refinement/string_constraint_generator_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,16 +482,14 @@ std::pair<exprt, string_constraintst> add_axioms_for_format(
std::string
utf16_constant_array_to_java(const array_exprt &arr, std::size_t length)
{
for(const auto &op : arr.operands())
PRECONDITION(op.id() == ID_constant);

std::wstring out(length, '?');
unsigned int c;

for(std::size_t i=0; i<arr.operands().size() && i<length; i++)
{
PRECONDITION(arr.operands()[i].id()==ID_constant);
bool conversion_failed=to_unsigned_integer(
to_constant_expr(arr.operands()[i]), c);
INVARIANT(!conversion_failed, "constant should be convertible to unsigned");
out[i]=c;
}
out[i] = numeric_cast_v<unsigned>(to_constant_expr(arr.operands()[i]));
Copy link
Collaborator

Choose a reason for hiding this comment

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

The above PRECONDITION is rather redundant.

Copy link
Member Author

Choose a reason for hiding this comment

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

I do like it as it clarifies the contract here well; will move up.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Having the two loops, esp. with different iteration control does seem a bit unnecessary.


return utf16_native_endian_to_java(out);
}

Expand Down Expand Up @@ -520,12 +518,11 @@ std::pair<exprt, string_constraintst> add_axioms_for_format(
const array_string_exprt res =
char_array_of_pointer(array_pool, f.arguments()[1], f.arguments()[0]);
const array_string_exprt s1 = get_string_expr(array_pool, f.arguments()[2]);
unsigned int length;

if(s1.length().id()==ID_constant &&
s1.content().id()==ID_array &&
!to_unsigned_integer(to_constant_expr(s1.length()), length))
if(s1.length().id() == ID_constant && s1.content().id() == ID_array)
{
const auto length =
numeric_cast_v<std::size_t>(to_constant_expr(s1.length()));
std::string s=utf16_constant_array_to_java(
to_array_expr(s1.content()), length);
// List of arguments after s
Expand Down
1 change: 1 addition & 0 deletions src/util/arith_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ bool to_integer(const exprt &expr, mp_integer &int_value);
bool to_integer(const constant_exprt &expr, mp_integer &int_value);

// returns 'true' on error
DEPRECATED("Use numeric_cast<unsigned>(e) instead")
bool to_unsigned_integer(const constant_exprt &expr, unsigned &uint_value);

/// Numerical cast provides a unified way of converting from one numerical type
Expand Down