Skip to content

Use numeric_cast_v<std::size_t> instead of deprecated integer2size_t [blocks: #2310] #3051

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
Nov 9, 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
3 changes: 2 additions & 1 deletion src/analyses/goto_rw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ void rw_range_sett::get_objects_byte_extract(
be.id()==ID_byte_extract_little_endian,
ns);
assert(index<std::numeric_limits<size_t>::max());
range_spect offset=range_start + map.map_bit(integer2size_t(index));
range_spect offset =
range_start + map.map_bit(numeric_cast_v<std::size_t>(index));
get_objects_rec(mode, be.op(), offset, size);
}
}
Expand Down
21 changes: 11 additions & 10 deletions src/ansi-c/c_typecheck_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ exprt c_typecheck_baset::do_initializer_rec(
if(mp_integer(tmp.operands().size())>array_size)
{
// cut off long strings. gcc does a warning for this
tmp.operands().resize(integer2size_t(array_size));
tmp.operands().resize(numeric_cast_v<std::size_t>(array_size));
tmp.type()=type;
}
else if(mp_integer(tmp.operands().size())<array_size)
Expand All @@ -123,7 +123,7 @@ exprt c_typecheck_baset::do_initializer_rec(
<< to_string(full_type.subtype()) << "'" << eom;
throw 0;
}
tmp.operands().resize(integer2size_t(array_size), *zero);
tmp.operands().resize(numeric_cast_v<std::size_t>(array_size), *zero);
}
}

Expand Down Expand Up @@ -167,7 +167,7 @@ exprt c_typecheck_baset::do_initializer_rec(
if(mp_integer(tmp2.operands().size())>array_size)
{
// cut off long strings. gcc does a warning for this
tmp2.operands().resize(integer2size_t(array_size));
tmp2.operands().resize(numeric_cast_v<std::size_t>(array_size));
tmp2.type()=type;
}
else if(mp_integer(tmp2.operands().size())<array_size)
Expand All @@ -183,7 +183,7 @@ exprt c_typecheck_baset::do_initializer_rec(
<< to_string(full_type.subtype()) << "'" << eom;
throw 0;
}
tmp2.operands().resize(integer2size_t(array_size), *zero);
tmp2.operands().resize(numeric_cast_v<std::size_t>(array_size), *zero);
}
}

Expand Down Expand Up @@ -323,7 +323,7 @@ void c_typecheck_baset::designator_enter(
throw 0;
}

entry.size=integer2size_t(array_size);
entry.size = numeric_cast_v<std::size_t>(array_size);
entry.subtype=array_type.subtype();
}
}
Expand All @@ -341,7 +341,7 @@ void c_typecheck_baset::designator_enter(
throw 0;
}

entry.size=integer2size_t(vector_size);
entry.size = numeric_cast_v<std::size_t>(vector_size);
entry.subtype=vector_type.subtype();
}
else
Expand Down Expand Up @@ -410,7 +410,8 @@ exprt::operandst::const_iterator c_typecheck_baset::do_designated_initializer(
<< to_string(full_type.subtype()) << "'" << eom;
throw 0;
}
dest->operands().resize(integer2size_t(index) + 1, *zero);
dest->operands().resize(
numeric_cast_v<std::size_t>(index) + 1, *zero);

// todo: adjust type!
}
Expand All @@ -424,7 +425,7 @@ exprt::operandst::const_iterator c_typecheck_baset::do_designated_initializer(
}
}

dest=&(dest->operands()[integer2size_t(index)]);
dest = &(dest->operands()[numeric_cast_v<std::size_t>(index)]);
}
else if(full_type.id()==ID_struct)
{
Expand Down Expand Up @@ -730,8 +731,8 @@ designatort c_typecheck_baset::make_designator(
throw 0;
}

entry.index=integer2size_t(index);
entry.size=integer2size_t(size);
entry.index = numeric_cast_v<std::size_t>(index);
entry.size = numeric_cast_v<std::size_t>(size);
entry.subtype=full_type.subtype();
}
else if(full_type.id()==ID_struct ||
Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/c_typecheck_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ void c_typecheck_baset::typecheck_c_bit_field_type(c_bit_field_typet &type)
throw 0;
}

type.set_width(integer2size_t(i));
type.set_width(numeric_cast_v<std::size_t>(i));
type.remove(ID_size);
}

Expand Down
10 changes: 5 additions & 5 deletions src/ansi-c/padding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ static void add_padding_msvc(struct_typet &type, const namespacet &ns)
{
const mp_integer pad_bytes = a - displacement;
std::size_t pad_bits =
integer2size_t(pad_bytes * config.ansi_c.char_width);
numeric_cast_v<std::size_t>(pad_bytes * config.ansi_c.char_width);
it = pad(components, it, pad_bits);
offset += pad_bytes;
}
Expand Down Expand Up @@ -262,7 +262,7 @@ static void add_padding_msvc(struct_typet &type, const namespacet &ns)
{
const mp_integer pad_bytes = a - displacement;
const std::size_t pad_bits =
integer2size_t(pad_bytes * config.ansi_c.char_width);
numeric_cast_v<std::size_t>(pad_bytes * config.ansi_c.char_width);
pad(components, components.end(), pad_bits);
offset += pad_bytes;
}
Expand Down Expand Up @@ -392,7 +392,7 @@ static void add_padding_gcc(struct_typet &type, const namespacet &ns)
{
const mp_integer pad_bytes = a - displacement;
const std::size_t pad_bits =
integer2size_t(pad_bytes * config.ansi_c.char_width);
numeric_cast_v<std::size_t>(pad_bytes * config.ansi_c.char_width);
it = pad(components, it, pad_bits);
offset += pad_bytes;
}
Expand Down Expand Up @@ -433,7 +433,7 @@ static void add_padding_gcc(struct_typet &type, const namespacet &ns)
{
mp_integer pad_bytes = max_alignment - displacement;
std::size_t pad_bits =
integer2size_t(pad_bytes * config.ansi_c.char_width);
numeric_cast_v<std::size_t>(pad_bytes * config.ansi_c.char_width);
pad(components, components.end(), pad_bits);
}
}
Expand Down Expand Up @@ -491,7 +491,7 @@ void add_padding(union_typet &type, const namespacet &ns)
max_alignment_bits-(size_bits%max_alignment_bits);

unsignedbv_typet padding_type(
integer2size_t(size_bits+padding_bits));
numeric_cast_v<std::size_t>(size_bits + padding_bits));

struct_typet::componentt component;
component.type()=padding_type;
Expand Down
39 changes: 21 additions & 18 deletions src/goto-programs/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ exprt interpretert::get_value(
}

// Retrieve the value for each member in the array
result.reserve_operands(integer2size_t(count));
result.reserve_operands(numeric_cast_v<std::size_t>(count));
for(mp_integer i=0; i<count; ++i)
{
const exprt operand=get_value(
Expand Down Expand Up @@ -568,7 +568,7 @@ exprt interpretert::get_value(
}

// Retrieve the value for each member in the array
result.reserve_operands(integer2size_t(count));
result.reserve_operands(numeric_cast_v<std::size_t>(count));
for(mp_integer i=0; i<count; ++i)
{
const exprt operand=get_value(type.subtype(), rhs,
Expand All @@ -580,35 +580,36 @@ exprt interpretert::get_value(
else if(real_type.id()==ID_floatbv)
{
ieee_floatt f(to_floatbv_type(type));
f.unpack(rhs[integer2size_t(offset)]);
f.unpack(rhs[numeric_cast_v<std::size_t>(offset)]);
return f.to_expr();
}
else if(real_type.id()==ID_fixedbv)
{
fixedbvt f;
f.from_integer(rhs[integer2size_t(offset)]);
f.from_integer(rhs[numeric_cast_v<std::size_t>(offset)]);
return f.to_expr();
}
else if(real_type.id()==ID_bool)
{
if(rhs[integer2size_t(offset)]!=0)
if(rhs[numeric_cast_v<std::size_t>(offset)] != 0)
return true_exprt();
else
false_exprt();
}
else if(real_type.id()==ID_c_bool)
{
return from_integer(rhs[integer2size_t(offset)]!=0?1:0, type);
return from_integer(
rhs[numeric_cast_v<std::size_t>(offset)] != 0 ? 1 : 0, type);
}
else if(real_type.id() == ID_pointer)
{
if(rhs[integer2size_t(offset)]==0)
if(rhs[numeric_cast_v<std::size_t>(offset)] == 0)
return null_pointer_exprt(to_pointer_type(real_type)); // NULL pointer

if(rhs[integer2size_t(offset)]<memory.size())
if(rhs[numeric_cast_v<std::size_t>(offset)] < memory.size())
{
// We want the symbol pointed to
mp_integer address=rhs[integer2size_t(offset)];
mp_integer address = rhs[numeric_cast_v<std::size_t>(offset)];
irep_idt identifier=address_to_identifier(address);
mp_integer offset=address_to_offset(address);
const typet type=get_type(identifier);
Expand All @@ -631,16 +632,18 @@ exprt interpretert::get_value(
return std::move(index_expr);
}

error() << "interpreter: invalid pointer " << rhs[integer2size_t(offset)]
<< " > object count " << memory.size() << eom;
error() << "interpreter: invalid pointer "
<< rhs[numeric_cast_v<std::size_t>(offset)] << " > object count "
<< memory.size() << eom;

throw "interpreter: reading from invalid pointer";
}
else if(real_type.id()==ID_string)
{
// Strings are currently encoded by their irep_idt ID.
return constant_exprt(
get_string_container().get_string(rhs[integer2size_t(offset)].to_long()),
get_string_container().get_string(
numeric_cast_v<std::size_t>(rhs[numeric_cast_v<std::size_t>(offset)])),
type);
}

Expand Down Expand Up @@ -680,8 +683,8 @@ void interpretert::execute_assign()
side_effect_exprt side_effect=to_side_effect_expr(code_assign.rhs());
if(side_effect.get_statement()==ID_nondet)
{
mp_integer address=
integer2size_t(evaluate_address(code_assign.lhs()));
mp_integer address =
numeric_cast_v<std::size_t>(evaluate_address(code_assign.lhs()));

mp_integer size=
get_size(code_assign.lhs().type());
Expand Down Expand Up @@ -710,11 +713,11 @@ void interpretert::assign(
{
status() << total_steps << " ** assigning "
<< address_to_identifier(address_val) << "["
<< address_to_offset(address_val) << "]:="
<< rhs[integer2size_t(i)]
<< "\n" << eom;
<< address_to_offset(address_val)
<< "]:=" << rhs[numeric_cast_v<std::size_t>(i)] << "\n"
<< eom;
}
cell.value=rhs[integer2size_t(i)];
cell.value = rhs[numeric_cast_v<std::size_t>(i)];
if(cell.initialized==memory_cellt::initializedt::UNKNOWN)
cell.initialized=memory_cellt::initializedt::WRITTEN_BEFORE_READ;
}
Expand Down
18 changes: 10 additions & 8 deletions src/goto-programs/interpreter_evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void interpretert::read_unbounded(
mp_vectort &dest) const
{
// copy memory region
std::size_t address_val=integer2size_t(address);
std::size_t address_val = numeric_cast_v<std::size_t>(address);
const mp_integer offset=address_to_offset(address_val);
const mp_integer alloc_size=
base_address_to_actual_size(address_val-offset);
Expand All @@ -61,7 +61,8 @@ void interpretert::read_unbounded(

if((address+i)<memory.size())
{
const memory_cellt &cell=memory[integer2size_t(address+i)];
const memory_cellt &cell =
memory[numeric_cast_v<std::size_t>(address + i)];
value=cell.value;
if(cell.initialized==memory_cellt::initializedt::UNKNOWN)
cell.initialized=memory_cellt::initializedt::READ_BEFORE_WRITTEN;
Expand Down Expand Up @@ -315,7 +316,7 @@ void interpretert::evaluate(
{
if(expr.type().id()==ID_struct)
{
dest.reserve(integer2size_t(get_size(expr.type())));
dest.reserve(numeric_cast_v<std::size_t>(get_size(expr.type())));
bool error=false;

forall_operands(it, expr)
Expand Down Expand Up @@ -418,7 +419,7 @@ void interpretert::evaluate(
else if(expr.id()==ID_struct)
{
if(!unbounded_size(expr.type()))
dest.reserve(integer2size_t(get_size(expr.type())));
dest.reserve(numeric_cast_v<std::size_t>(get_size(expr.type())));

bool error=false;

Expand Down Expand Up @@ -959,7 +960,7 @@ void interpretert::evaluate(
{
if(!unbounded_size(expr.type()))
{
dest.resize(integer2size_t(get_size(expr.type())));
dest.resize(numeric_cast_v<std::size_t>(get_size(expr.type())));
read(address, dest);
}
else
Expand Down Expand Up @@ -1026,7 +1027,7 @@ void interpretert::evaluate(

if(size.size()==1)
{
std::size_t size_int=integer2size_t(size[0]);
std::size_t size_int = numeric_cast_v<std::size_t>(size[0]);
for(std::size_t i=0; i<size_int; ++i)
evaluate(expr.op0(), dest);
return;
Expand All @@ -1052,10 +1053,11 @@ void interpretert::evaluate(
mp_integer need_size=(where_idx+1)*subtype_size;

if(dest.size()<need_size)
dest.resize(integer2size_t(need_size), 0);
dest.resize(numeric_cast_v<std::size_t>(need_size), 0);

for(std::size_t i=0; i<new_value.size(); ++i)
dest[integer2size_t((where_idx*subtype_size)+i)]=new_value[i];
dest[numeric_cast_v<std::size_t>((where_idx * subtype_size) + i)] =
new_value[i];

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/goto-programs/remove_const_function_pointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ bool remove_const_function_pointerst::try_resolve_index_of(
if(try_resolve_index_value(index_expr.index(), value))
{
expressionst array_out_functions;
const exprt &func_expr=
potential_array_expr.operands()[integer2size_t(value)];
const exprt &func_expr =
potential_array_expr.operands()[numeric_cast_v<std::size_t>(value)];
bool value_const=false;
bool resolved_value=
try_resolve_expression(func_expr, array_out_functions, value_const);
Expand Down
4 changes: 2 additions & 2 deletions src/goto-programs/remove_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static void remove_vector(exprt &expr)
// do component-wise:
// x+y -> vector(x[0]+y[0],x[1]+y[1],...)
array_exprt array_expr(array_type);
array_expr.operands().resize(integer2size_t(dimension));
array_expr.operands().resize(numeric_cast_v<std::size_t>(dimension));

for(std::size_t i=0; i<array_expr.operands().size(); i++)
{
Expand All @@ -125,7 +125,7 @@ static void remove_vector(exprt &expr)
// do component-wise:
// -x -> vector(-x[0],-x[1],...)
array_exprt array_expr(array_type);
array_expr.operands().resize(integer2size_t(dimension));
array_expr.operands().resize(numeric_cast_v<std::size_t>(dimension));

for(std::size_t i=0; i<array_expr.operands().size(); i++)
{
Expand Down
3 changes: 2 additions & 1 deletion src/goto-programs/vcd_goto_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Date: June 2011

#include <ctime>

#include <util/arith_tools.h>
#include <util/numbering.h>
#include <util/pointer_offset_size.h>

Expand Down Expand Up @@ -62,7 +63,7 @@ std::string as_vcd_binary(
const auto width = pointer_offset_bits(type, ns);

if(width.has_value())
return std::string(integer2size_t(*width), 'x');
return std::string(numeric_cast_v<std::size_t>(*width), 'x');
else
return "";
}
Expand Down
2 changes: 1 addition & 1 deletion src/solvers/flattening/boolbv_byte_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bvt boolbvt::convert_byte_update(const byte_update_exprt &expr)
if(little_endian)
{
for(std::size_t i=0; i<update_width; i++)
bv[integer2size_t(offset+i)]=value_bv[i];
bv[numeric_cast_v<std::size_t>(offset + i)] = value_bv[i];
}
else
{
Expand Down
Loading