Skip to content

Commit db7bff3

Browse files
author
Daniel Kroening
authored
Merge pull request #3065 from diffblue/to_unsigned_integer
remove instances of to_unsigned_integer
2 parents 4455dee + 0209196 commit db7bff3

File tree

4 files changed

+13
-20
lines changed

4 files changed

+13
-20
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,9 +1069,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
10691069
{
10701070
PRECONDITION(!i_it->args.empty());
10711071

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

10771075
a_entry.first->second.successors.push_back(target);
@@ -1094,9 +1092,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
10941092
{
10951093
if(is_label)
10961094
{
1097-
unsigned target;
1098-
bool ret=to_unsigned_integer(to_constant_expr(arg), target);
1099-
DATA_INVARIANT(!ret, "target expected to be unsigned integer");
1095+
auto target = numeric_cast_v<unsigned>(to_constant_expr(arg));
11001096
targets.insert(target);
11011097
a_entry.first->second.successors.push_back(target);
11021098
}

jbmc/src/java_bytecode/java_local_variable_table.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ static bool is_store_to_slot(
193193
{
194194
// Store with an argument:
195195
const auto &arg=inst.args[0];
196-
bool ret=to_unsigned_integer(to_constant_expr(arg), storeslotidx);
197-
CHECK_RETURN(!ret);
196+
storeslotidx = numeric_cast_v<unsigned>(to_constant_expr(arg));
198197
}
199198
else
200199
{

src/solvers/refinement/string_constraint_generator_format.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -482,16 +482,14 @@ std::pair<exprt, string_constraintst> add_axioms_for_format(
482482
std::string
483483
utf16_constant_array_to_java(const array_exprt &arr, std::size_t length)
484484
{
485+
for(const auto &op : arr.operands())
486+
PRECONDITION(op.id() == ID_constant);
487+
485488
std::wstring out(length, '?');
486-
unsigned int c;
489+
487490
for(std::size_t i=0; i<arr.operands().size() && i<length; i++)
488-
{
489-
PRECONDITION(arr.operands()[i].id()==ID_constant);
490-
bool conversion_failed=to_unsigned_integer(
491-
to_constant_expr(arr.operands()[i]), c);
492-
INVARIANT(!conversion_failed, "constant should be convertible to unsigned");
493-
out[i]=c;
494-
}
491+
out[i] = numeric_cast_v<unsigned>(to_constant_expr(arr.operands()[i]));
492+
495493
return utf16_native_endian_to_java(out);
496494
}
497495

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

525-
if(s1.length().id()==ID_constant &&
526-
s1.content().id()==ID_array &&
527-
!to_unsigned_integer(to_constant_expr(s1.length()), length))
522+
if(s1.length().id() == ID_constant && s1.content().id() == ID_array)
528523
{
524+
const auto length =
525+
numeric_cast_v<std::size_t>(to_constant_expr(s1.length()));
529526
std::string s=utf16_constant_array_to_java(
530527
to_array_expr(s1.content()), length);
531528
// List of arguments after s

src/util/arith_tools.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ bool to_integer(const exprt &expr, mp_integer &int_value);
2929
bool to_integer(const constant_exprt &expr, mp_integer &int_value);
3030

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

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

0 commit comments

Comments
 (0)