Skip to content

Commit 009e7ae

Browse files
tautschnigDaniel Kroening
authored andcommitted
Use non-deprecated variant of to_integer
to_integer requires a constant_exprt as first argument.
1 parent adb3d7b commit 009e7ae

11 files changed

+41
-26
lines changed

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2592,7 +2592,7 @@ exprt c_typecheck_baset::do_special_functions(
25922592
arg1=1;
25932593
else if(expr.arguments()[1].is_false())
25942594
arg1=0;
2595-
else if(to_integer(expr.arguments()[1], arg1))
2595+
else if(to_integer(to_constant_expr(expr.arguments()[1]), arg1))
25962596
{
25972597
error().source_location = f_op.source_location();
25982598
error() << "__builtin_object_size expects constant as second argument, "

src/ansi-c/c_typecheck_initializer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ designatort c_typecheck_baset::make_designator(
726726

727727
mp_integer index, size;
728728

729-
if(to_integer(tmp_index, index))
729+
if(to_integer(to_constant_expr(tmp_index), index))
730730
{
731731
error().source_location = d_op.op0().source_location();
732732
error() << "expected constant array index designator" << eom;

src/ansi-c/c_typecheck_type.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ void c_typecheck_baset::typecheck_custom_type(typet &type)
316316
make_constant_index(size_expr);
317317

318318
mp_integer size_int;
319-
if(to_integer(size_expr, size_int))
319+
if(to_integer(to_constant_expr(size_expr), size_int))
320320
{
321321
error().source_location=source_location;
322322
error() << "failed to convert bit vector width to constant" << eom;
@@ -354,7 +354,7 @@ void c_typecheck_baset::typecheck_custom_type(typet &type)
354354
make_constant_index(f_expr);
355355

356356
mp_integer f_int;
357-
if(to_integer(f_expr, f_int))
357+
if(to_integer(to_constant_expr(f_expr), f_int))
358358
{
359359
error().source_location = fraction_source_location;
360360
error() << "failed to convert number of fraction bits to constant" << eom;
@@ -386,7 +386,7 @@ void c_typecheck_baset::typecheck_custom_type(typet &type)
386386
make_constant_index(f_expr);
387387

388388
mp_integer f_int;
389-
if(to_integer(f_expr, f_int))
389+
if(to_integer(to_constant_expr(f_expr), f_int))
390390
{
391391
error().source_location = fraction_source_location;
392392
error() << "failed to convert number of fraction bits to constant" << eom;
@@ -560,7 +560,7 @@ void c_typecheck_baset::typecheck_array_type(array_typet &type)
560560
if(tmp_size.is_constant())
561561
{
562562
mp_integer s;
563-
if(to_integer(tmp_size, s))
563+
if(to_integer(to_constant_expr(tmp_size), s))
564564
{
565565
error().source_location = size_source_location;
566566
error() << "failed to convert constant: "
@@ -684,7 +684,7 @@ void c_typecheck_baset::typecheck_vector_type(vector_typet &type)
684684
make_constant_index(size);
685685

686686
mp_integer s;
687-
if(to_integer(size, s))
687+
if(to_integer(to_constant_expr(size), s))
688688
{
689689
error().source_location=source_location;
690690
error() << "failed to convert constant: "
@@ -1174,7 +1174,9 @@ void c_typecheck_baset::typecheck_c_enum_type(typet &type)
11741174
value=1;
11751175
else if(tmp_v.is_false())
11761176
value=0;
1177-
else if(!to_integer(tmp_v, value))
1177+
else if(
1178+
tmp_v.id() == ID_constant &&
1179+
!to_integer(to_constant_expr(tmp_v), value))
11781180
{
11791181
}
11801182
else
@@ -1384,7 +1386,7 @@ void c_typecheck_baset::typecheck_c_bit_field_type(c_bit_field_typet &type)
13841386
typecheck_expr(width_expr);
13851387
make_constant_index(width_expr);
13861388

1387-
if(to_integer(width_expr, i))
1389+
if(to_integer(to_constant_expr(width_expr), i))
13881390
{
13891391
error().source_location=type.source_location();
13901392
error() << "failed to convert bit field width" << eom;

src/cpp/cpp_constructor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ optionalt<codet> cpp_typecheckt::cpp_constructor(
6868
make_constant_index(tmp_size);
6969

7070
mp_integer s;
71-
if(to_integer(tmp_size, s))
71+
if(to_integer(to_constant_expr(tmp_size), s))
7272
{
7373
error().source_location=source_location;
7474
error() << "array size `" << to_string(size_expr)

src/cpp/cpp_destructor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ optionalt<codet> cpp_typecheckt::cpp_destructor(
4545
make_constant_index(tmp_size);
4646

4747
mp_integer s;
48-
if(to_integer(tmp_size, s))
48+
if(to_integer(to_constant_expr(tmp_size), s))
4949
{
5050
error().source_location=source_location;
5151
error() << "array size `" << to_string(size_expr)

src/cpp/cpp_instantiate_template.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ std::string cpp_typecheckt::template_suffix(
6363
i=1;
6464
else if(e.is_false())
6565
i=0;
66-
else if(to_integer(e, i))
66+
else if(to_integer(to_constant_expr(e), i))
6767
{
6868
error().source_location = expr.find_source_location();
6969
error() << "template argument expression expected to be "

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
532532
if(value.is_not_nil() && value.id() == ID_constant)
533533
{
534534
mp_integer i;
535-
to_integer(value, i);
535+
to_integer(to_constant_expr(value), i);
536536
if(i!=0)
537537
{
538538
error().source_location = declarator.name().source_location();

src/cpp/cpp_typecheck_enum_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void cpp_typecheckt::typecheck_enum_body(symbolt &enum_symbol)
4040
typecheck_expr(value);
4141
implicit_typecast(value, c_enum_type.subtype());
4242
make_constant(value);
43-
if(to_integer(value, i))
43+
if(to_integer(to_constant_expr(value), i))
4444
{
4545
error().source_location=value.find_source_location();
4646
error() << "failed to produce integer for enum constant" << eom;

src/goto-programs/builtin_functions.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ void goto_convertt::do_prob_uniform(
8282

8383
mp_integer lb, ub;
8484

85-
if(to_integer(arguments[0], lb) ||
86-
to_integer(arguments[1], ub))
85+
if(
86+
to_integer(to_constant_expr(arguments[0]), lb) ||
87+
to_integer(to_constant_expr(arguments[1]), ub))
8788
{
8889
error().source_location=function.find_source_location();
8990
error() << "error converting operands" << eom;
@@ -147,10 +148,21 @@ void goto_convertt::do_prob_coin(
147148
throw 0;
148149
}
149150

151+
if(
152+
arguments[1].type().id() != ID_unsignedbv ||
153+
arguments[1].id() != ID_constant)
154+
{
155+
error().source_location = function.find_source_location();
156+
error() << "`" << identifier << "' expected second operand to be "
157+
<< "a constant literal of type unsigned long" << eom;
158+
throw 0;
159+
}
160+
150161
mp_integer num, den;
151162

152-
if(to_integer(arguments[0], num) ||
153-
to_integer(arguments[1], den))
163+
if(
164+
to_integer(to_constant_expr(arguments[0]), num) ||
165+
to_integer(to_constant_expr(arguments[1]), den))
154166
{
155167
error().source_location=function.find_source_location();
156168
error() << "error converting operands" << eom;

src/util/simplify_expr_int.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ bool simplify_exprt::simplify_inequality_constant(exprt &expr)
17721772
if(it->is_constant())
17731773
{
17741774
mp_integer i;
1775-
if(!to_integer(*it, i))
1775+
if(!to_integer(to_constant_expr(*it), i))
17761776
{
17771777
constant+=i;
17781778
*it=from_integer(0, it->type());

0 commit comments

Comments
 (0)