28
28
#include < util/xml.h>
29
29
30
30
#ifdef DEBUG
31
- #include < iostream>
32
- #include < util/format_expr.h>
33
- #include < util/format_type.h>
31
+ # include < iostream>
34
32
#endif
35
33
36
34
#include " add_failed_symbols.h"
@@ -184,7 +182,7 @@ void value_sett::output(std::ostream &out, const std::string &indent) const
184
182
stream << " <" << format (o) << " , " ;
185
183
186
184
if (o_it->second )
187
- stream << *o_it->second ;
185
+ stream << format ( *o_it->second ) ;
188
186
else
189
187
stream << ' *' ;
190
188
@@ -261,7 +259,7 @@ exprt value_sett::to_expr(const object_map_dt::value_type &it) const
261
259
od.object ()=object;
262
260
263
261
if (it.second )
264
- od.offset () = from_integer ( *it.second , c_index_type ()) ;
262
+ od.offset () = *it.second ;
265
263
266
264
od.type ()=od.object ().type ();
267
265
@@ -352,7 +350,7 @@ bool value_sett::eval_pointer_offset(
352
350
it=object_map.begin ();
353
351
it!=object_map.end ();
354
352
it++)
355
- if (!it->second )
353
+ if (!it->second || !it-> second -> is_constant () )
356
354
return false ;
357
355
else
358
356
{
@@ -362,7 +360,8 @@ bool value_sett::eval_pointer_offset(
362
360
if (!ptr_offset.has_value ())
363
361
return false ;
364
362
365
- *ptr_offset += *it->second ;
363
+ *ptr_offset +=
364
+ numeric_cast_v<mp_integer>(to_constant_expr (*it->second ));
366
365
367
366
if (mod && *ptr_offset != previous_offset)
368
367
return false ;
@@ -623,7 +622,7 @@ void value_sett::get_value_set_rec(
623
622
insert (
624
623
dest,
625
624
exprt (ID_null_object, to_pointer_type (expr.type ()).base_type ()),
626
- mp_integer{ 0 } );
625
+ from_integer ( 0 , c_index_type ()) );
627
626
}
628
627
else if (
629
628
expr.type ().id () == ID_unsignedbv || expr.type ().id () == ID_signedbv)
@@ -655,7 +654,10 @@ void value_sett::get_value_set_rec(
655
654
656
655
if (op.is_zero ())
657
656
{
658
- insert (dest, exprt (ID_null_object, empty_typet{}), mp_integer{0 });
657
+ insert (
658
+ dest,
659
+ exprt (ID_null_object, empty_typet{}),
660
+ from_integer (0 , c_index_type ()));
659
661
}
660
662
else
661
663
{
@@ -696,15 +698,14 @@ void value_sett::get_value_set_rec(
696
698
throw expr.id_string ()+" expected to have at least two operands" ;
697
699
698
700
object_mapt pointer_expr_set;
699
- std::optional<mp_integer> i ;
701
+ std::optional<exprt> additional_offset ;
700
702
701
703
// special case for plus/minus and exactly one pointer
702
704
std::optional<exprt> ptr_operand;
703
705
if (
704
706
expr.type ().id () == ID_pointer &&
705
707
(expr.id () == ID_plus || expr.id () == ID_minus))
706
708
{
707
- bool non_const_offset = false ;
708
709
for (const auto &op : expr.operands ())
709
710
{
710
711
if (op.type ().id () == ID_pointer)
@@ -717,24 +718,20 @@ void value_sett::get_value_set_rec(
717
718
718
719
ptr_operand = op;
719
720
}
720
- else if (!non_const_offset)
721
+ else
721
722
{
722
- auto offset = numeric_cast<mp_integer>(op);
723
- if (!offset.has_value ())
724
- {
725
- i.reset ();
726
- non_const_offset = true ;
727
- }
723
+ if (!additional_offset.has_value ())
724
+ additional_offset = op;
728
725
else
729
726
{
730
- if (!i. has_value ())
731
- i = mp_integer{ 0 };
732
- i = *i + *offset ;
727
+ additional_offset = plus_exprt{
728
+ *additional_offset,
729
+ typecast_exprt::conditional_cast (op, additional_offset-> type ())} ;
733
730
}
734
731
}
735
732
}
736
733
737
- if (ptr_operand.has_value () && i .has_value ())
734
+ if (ptr_operand.has_value () && additional_offset .has_value ())
738
735
{
739
736
typet pointer_base_type =
740
737
to_pointer_type (ptr_operand->type ()).base_type ();
@@ -745,18 +742,22 @@ void value_sett::get_value_set_rec(
745
742
746
743
if (!size.has_value () || (*size) == 0 )
747
744
{
748
- i .reset ();
745
+ additional_offset .reset ();
749
746
}
750
747
else
751
748
{
752
- *i *= *size;
749
+ additional_offset = mult_exprt{
750
+ *additional_offset, from_integer (*size, additional_offset->type ())};
753
751
754
752
if (expr.id ()==ID_minus)
755
753
{
756
754
DATA_INVARIANT (
757
755
to_minus_expr (expr).lhs () == *ptr_operand,
758
756
" unexpected subtraction of pointer from integer" );
759
- i->negate ();
757
+ DATA_INVARIANT (
758
+ additional_offset->type ().id () != ID_unsignedbv,
759
+ " offset type must support negation" );
760
+ additional_offset = unary_minus_exprt{*additional_offset};
760
761
}
761
762
}
762
763
}
@@ -790,8 +791,12 @@ void value_sett::get_value_set_rec(
790
791
offsett offset = it->second ;
791
792
792
793
// adjust by offset
793
- if (offset && i.has_value ())
794
- *offset += *i;
794
+ if (offset && additional_offset.has_value ())
795
+ {
796
+ offset = plus_exprt{
797
+ *offset,
798
+ typecast_exprt::conditional_cast (*additional_offset, offset->type ())};
799
+ }
795
800
else
796
801
offset.reset ();
797
802
@@ -871,7 +876,7 @@ void value_sett::get_value_set_rec(
871
876
dynamic_object.set_instance (location_number);
872
877
dynamic_object.valid ()=true_exprt ();
873
878
874
- insert (dest, dynamic_object, mp_integer{ 0 } );
879
+ insert (dest, dynamic_object, from_integer ( 0 , c_index_type ()) );
875
880
}
876
881
else if (statement==ID_cpp_new ||
877
882
statement==ID_cpp_new_array)
@@ -884,7 +889,7 @@ void value_sett::get_value_set_rec(
884
889
dynamic_object.set_instance (location_number);
885
890
dynamic_object.valid ()=true_exprt ();
886
891
887
- insert (dest, dynamic_object, mp_integer{ 0 } );
892
+ insert (dest, dynamic_object, from_integer ( 0 , c_index_type ()) );
888
893
}
889
894
else
890
895
insert (dest, exprt (ID_unknown, original_type));
@@ -1336,7 +1341,7 @@ void value_sett::get_reference_set_rec(
1336
1341
to_array_type (expr.type ()).element_type ().id () == ID_array)
1337
1342
insert (dest, expr);
1338
1343
else
1339
- insert (dest, expr, mp_integer{ 0 } );
1344
+ insert (dest, expr, from_integer ( 0 , c_index_type ()) );
1340
1345
1341
1346
return ;
1342
1347
}
@@ -1365,7 +1370,7 @@ void value_sett::get_reference_set_rec(
1365
1370
1366
1371
const index_exprt &index_expr=to_index_expr (expr);
1367
1372
const exprt &array=index_expr.array ();
1368
- const exprt &offset= index_expr.index ();
1373
+ const exprt &index = index_expr.index ();
1369
1374
1370
1375
DATA_INVARIANT (
1371
1376
array.type ().id () == ID_array, " index takes array-typed operand" );
@@ -1393,22 +1398,22 @@ void value_sett::get_reference_set_rec(
1393
1398
from_integer (0 , c_index_type ()));
1394
1399
1395
1400
offsett o = a_it->second ;
1396
- const auto i = numeric_cast<mp_integer>(offset);
1397
1401
1398
- if (offset.is_zero ())
1399
- {
1400
- }
1401
- else if (i.has_value () && o)
1402
+ if (!index.is_zero () && o.has_value ())
1402
1403
{
1403
1404
auto size = pointer_offset_size (array_type.element_type (), ns);
1404
1405
1405
1406
if (!size.has_value () || *size == 0 )
1406
1407
o.reset ();
1407
1408
else
1408
- *o = *i * (*size);
1409
+ {
1410
+ o = plus_exprt{
1411
+ *o,
1412
+ typecast_exprt::conditional_cast (
1413
+ mult_exprt{index, from_integer (*size, index.type ())},
1414
+ o->type ())};
1415
+ }
1409
1416
}
1410
- else
1411
- o.reset ();
1412
1417
1413
1418
insert (dest, deref_index_expr, o);
1414
1419
}
0 commit comments