Skip to content

Commit e082aed

Browse files
author
Daniel Kroening
committed
replace instances of to_unsigned_integer by numeric_cast
1 parent 2e84af4 commit e082aed

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,12 +1066,11 @@ codet java_bytecode_convert_methodt::convert_instructions(
10661066
{
10671067
PRECONDITION(!i_it->args.empty());
10681068

1069-
unsigned target;
1070-
bool ret=to_unsigned_integer(to_constant_expr(i_it->args[0]), target);
1071-
DATA_INVARIANT(!ret, "target expected to be unsigned integer");
1072-
targets.insert(target);
1069+
auto target=numeric_cast<unsigned>(to_constant_expr(i_it->args[0]));
1070+
DATA_INVARIANT(target.has_value(), "target expected to be unsigned integer");
1071+
targets.insert(target.value());
10731072

1074-
a_entry.first->second.successors.push_back(target);
1073+
a_entry.first->second.successors.push_back(target.value());
10751074

10761075
if(i_it->statement=="jsr" ||
10771076
i_it->statement=="jsr_w")
@@ -1091,11 +1090,10 @@ codet java_bytecode_convert_methodt::convert_instructions(
10911090
{
10921091
if(is_label)
10931092
{
1094-
unsigned target;
1095-
bool ret=to_unsigned_integer(to_constant_expr(arg), target);
1096-
DATA_INVARIANT(!ret, "target expected to be unsigned integer");
1097-
targets.insert(target);
1098-
a_entry.first->second.successors.push_back(target);
1093+
auto target=numeric_cast<unsigned>(to_constant_expr(arg));
1094+
DATA_INVARIANT(target.has_value(), "target expected to be unsigned integer");
1095+
targets.insert(target.value());
1096+
a_entry.first->second.successors.push_back(target.value());
10991097
}
11001098
is_label=!is_label;
11011099
}

jbmc/src/java_bytecode/java_local_variable_table.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,9 @@ 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+
auto v=numeric_cast<unsigned>(to_constant_expr(arg));
197+
CHECK_RETURN(v.has_value());
198+
storeslotidx=v.value();
198199
}
199200
else
200201
{

src/solvers/refinement/string_constraint_generator_format.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -483,14 +483,12 @@ std::string
483483
utf16_constant_array_to_java(const array_exprt &arr, std::size_t length)
484484
{
485485
std::wstring out(length, '?');
486-
unsigned int c;
487486
for(std::size_t i=0; i<arr.operands().size() && i<length; i++)
488487
{
489488
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;
489+
auto c=numeric_cast<unsigned>(to_constant_expr(arr.operands()[i]));
490+
INVARIANT(c.has_value(), "constant should be convertible to unsigned");
491+
out[i]=c.value();
494492
}
495493
return utf16_native_endian_to_java(out);
496494
}
@@ -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

525522
if(s1.length().id()==ID_constant &&
526-
s1.content().id()==ID_array &&
527-
!to_unsigned_integer(to_constant_expr(s1.length()), length))
523+
s1.content().id()==ID_array)
528524
{
525+
const auto length=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

0 commit comments

Comments
 (0)