Skip to content

Commit 7bf48c0

Browse files
author
Daniel Kroening
authored
Merge pull request #3047 from tautschnig/integer2unsigned
Use appropriate numeric_cast_v<T> instead of deprecated integer2unsigned
2 parents 28201d2 + 0c2f8c1 commit 7bf48c0

10 files changed

+21
-20
lines changed

src/ansi-c/expr2c.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,10 +2219,7 @@ std::string expr2ct::convert_array(
22192219
if(it==--src.operands().end())
22202220
break;
22212221

2222-
assert(it->is_constant());
2223-
mp_integer i;
2224-
to_integer(*it, i);
2225-
unsigned int ch=integer2unsigned(i);
2222+
const unsigned int ch = numeric_cast_v<unsigned>(*it);
22262223

22272224
if(last_was_hex)
22282225
{

src/solvers/flattening/boolbv_byte_update.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ bvt boolbvt::convert_byte_update(const byte_update_exprt &expr)
6060
bv_endianness_mapt map_op(op.type(), false, ns, boolbv_width);
6161
bv_endianness_mapt map_value(value.type(), false, ns, boolbv_width);
6262

63-
std::size_t offset_i=integer2unsigned(offset);
63+
const std::size_t offset_i = numeric_cast_v<std::size_t>(offset);
6464

6565
for(std::size_t i=0; i<update_width; i++)
6666
{

src/solvers/flattening/boolbv_extractbits.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ bvt boolbvt::convert_extractbits(const extractbits_exprt &expr)
5454
expr.find_source_location(),
5555
irep_pretty_diagnosticst{expr});
5656

57-
const std::size_t offset = integer2unsigned(lower_as_int);
57+
const std::size_t offset = numeric_cast_v<std::size_t>(lower_as_int);
5858

5959
bvt result_bv(src_bv.begin() + offset, src_bv.begin() + offset + bv_width);
6060

src/solvers/flattening/boolbv_replication.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ bvt boolbvt::convert_replication(const replication_exprt &expr)
2222
bvt bv;
2323
bv.resize(width);
2424

25-
const std::size_t u_times=integer2unsigned(times);
25+
const std::size_t u_times = numeric_cast_v<std::size_t>(times);
2626
const bvt &op = convert_bv(expr.op());
2727

2828
INVARIANT(

src/solvers/flattening/boolbv_width.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const boolbv_widtht::entryt &boolbv_widtht::get_entry(const typet &type) const
141141
if(total>(1<<30)) // realistic limit
142142
throw analysis_exceptiont("array too large for flattening");
143143

144-
entry.total_width=integer2unsigned(total);
144+
entry.total_width = numeric_cast_v<std::size_t>(total);
145145
}
146146
}
147147
else if(type_id==ID_vector)
@@ -162,13 +162,13 @@ const boolbv_widtht::entryt &boolbv_widtht::get_entry(const typet &type) const
162162
if(total>(1<<30)) // realistic limit
163163
analysis_exceptiont("vector too large for flattening");
164164

165-
entry.total_width=integer2unsigned(vector_size*sub_width);
165+
entry.total_width = numeric_cast_v<std::size_t>(vector_size * sub_width);
166166
}
167167
}
168168
else if(type_id==ID_complex)
169169
{
170-
std::size_t sub_width=operator()(type.subtype());
171-
entry.total_width=integer2unsigned(2*sub_width);
170+
const mp_integer sub_width = operator()(type.subtype());
171+
entry.total_width = numeric_cast_v<std::size_t>(2 * sub_width);
172172
}
173173
else if(type_id==ID_code)
174174
{

src/solvers/flattening/boolbv_with.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ void boolbvt::convert_with_array(
152152

153153
if(op1_value>=0 && op1_value<size) // bounds check
154154
{
155-
std::size_t offset=integer2unsigned(op1_value*op2_bv.size());
155+
const std::size_t offset =
156+
numeric_cast_v<std::size_t>(op1_value * op2_bv.size());
156157

157158
for(std::size_t j=0; j<op2_bv.size(); j++)
158159
next_bv[offset+j]=op2_bv[j];
@@ -169,7 +170,7 @@ void boolbvt::convert_with_array(
169170

170171
literalt eq_lit=convert(equal_exprt(op1, counter));
171172

172-
std::size_t offset=integer2unsigned(i*op2_bv.size());
173+
const std::size_t offset = numeric_cast_v<std::size_t>(i * op2_bv.size());
173174

174175
for(std::size_t j=0; j<op2_bv.size(); j++)
175176
next_bv[offset+j]=

src/solvers/flattening/flatten_byte_operators.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ exprt flatten_byte_extract(
330330
const typet &offset_type=ns.follow(offset.type());
331331

332332
// get 'width'-many bytes, and concatenate
333-
std::size_t width_bytes=integer2unsigned(num_elements);
333+
const std::size_t width_bytes = numeric_cast_v<std::size_t>(num_elements);
334334
exprt::operandst op;
335335
op.reserve(width_bytes);
336336

@@ -567,10 +567,12 @@ exprt flatten_byte_update(
567567
// zero-extend the value, but only if needed
568568
exprt value_extended;
569569

570-
if(width>integer2unsigned(element_size)*8)
570+
if(width > element_size * 8)
571571
value_extended = concatenation_exprt(
572572
from_integer(
573-
0, unsignedbv_typet(width - integer2unsigned(element_size) * 8)),
573+
0,
574+
unsignedbv_typet(
575+
width - numeric_cast_v<std::size_t>(element_size) * 8)),
574576
src.value(),
575577
t);
576578
else

src/solvers/qbf/qbf_qube_core.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Author: CM Wintersteiger
1212
#include <cstring>
1313
#include <fstream>
1414

15+
#include <util/arith_tools.h>
1516
#include <util/invariant.h>
1617
#include <util/mp_arith.h>
1718

@@ -78,9 +79,9 @@ propt::resultt qbf_qube_coret::prop_solve()
7879
{
7980
mp_integer b(line.substr(2).c_str());
8081
if(b<0)
81-
assignment[integer2unsigned(b.negate())]=false;
82+
assignment[numeric_cast_v<std::size_t>(b.negate())] = false;
8283
else
83-
assignment[integer2unsigned(b)]=true;
84+
assignment[numeric_cast_v<std::size_t>(b)] = true;
8485
}
8586
else if(line=="s cnf 1")
8687
{

src/util/arith_tools.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ bool to_unsigned_integer(const constant_exprt &expr, unsigned &uint_value)
100100
return true;
101101
else
102102
{
103-
uint_value=integer2unsigned(i);
103+
uint_value = numeric_cast_v<unsigned>(i);
104104
return false;
105105
}
106106
}

src/util/config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ static unsigned unsigned_from_ns(
11361136
"symbol table configuration entry `" + id2string(id) +
11371137
"' must be convertible to mp_integer");
11381138

1139-
return integer2unsigned(int_value);
1139+
return numeric_cast_v<unsigned>(int_value);
11401140
}
11411141

11421142
void configt::set_from_symbol_table(

0 commit comments

Comments
 (0)