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,15 @@ 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 = simplify_expr (
797
+ plus_exprt{
798
+ *offset,
799
+ typecast_exprt::conditional_cast (
800
+ *additional_offset, offset->type ())},
801
+ ns);
802
+ }
795
803
else
796
804
offset.reset ();
797
805
@@ -871,7 +879,7 @@ void value_sett::get_value_set_rec(
871
879
dynamic_object.set_instance (location_number);
872
880
dynamic_object.valid ()=true_exprt ();
873
881
874
- insert (dest, dynamic_object, mp_integer{ 0 } );
882
+ insert (dest, dynamic_object, from_integer ( 0 , c_index_type ()) );
875
883
}
876
884
else if (statement==ID_cpp_new ||
877
885
statement==ID_cpp_new_array)
@@ -884,7 +892,7 @@ void value_sett::get_value_set_rec(
884
892
dynamic_object.set_instance (location_number);
885
893
dynamic_object.valid ()=true_exprt ();
886
894
887
- insert (dest, dynamic_object, mp_integer{ 0 } );
895
+ insert (dest, dynamic_object, from_integer ( 0 , c_index_type ()) );
888
896
}
889
897
else
890
898
insert (dest, exprt (ID_unknown, original_type));
@@ -1336,7 +1344,7 @@ void value_sett::get_reference_set_rec(
1336
1344
to_array_type (expr.type ()).element_type ().id () == ID_array)
1337
1345
insert (dest, expr);
1338
1346
else
1339
- insert (dest, expr, mp_integer{ 0 } );
1347
+ insert (dest, expr, from_integer ( 0 , c_index_type ()) );
1340
1348
1341
1349
return ;
1342
1350
}
@@ -1365,7 +1373,7 @@ void value_sett::get_reference_set_rec(
1365
1373
1366
1374
const index_exprt &index_expr=to_index_expr (expr);
1367
1375
const exprt &array=index_expr.array ();
1368
- const exprt &offset= index_expr.index ();
1376
+ const exprt &index = index_expr.index ();
1369
1377
1370
1378
DATA_INVARIANT (
1371
1379
array.type ().id () == ID_array, " index takes array-typed operand" );
@@ -1393,22 +1401,24 @@ void value_sett::get_reference_set_rec(
1393
1401
from_integer (0 , c_index_type ()));
1394
1402
1395
1403
offsett o = a_it->second ;
1396
- const auto i = numeric_cast<mp_integer>(offset);
1397
1404
1398
- if (offset.is_zero ())
1399
- {
1400
- }
1401
- else if (i.has_value () && o)
1405
+ if (!index.is_zero () && o.has_value ())
1402
1406
{
1403
1407
auto size = pointer_offset_size (array_type.element_type (), ns);
1404
1408
1405
1409
if (!size.has_value () || *size == 0 )
1406
1410
o.reset ();
1407
1411
else
1408
- *o = *i * (*size);
1412
+ {
1413
+ o = simplify_expr (
1414
+ plus_exprt{
1415
+ *o,
1416
+ typecast_exprt::conditional_cast (
1417
+ mult_exprt{index, from_integer (*size, index.type ())},
1418
+ o->type ())},
1419
+ ns);
1420
+ }
1409
1421
}
1410
- else
1411
- o.reset ();
1412
1422
1413
1423
insert (dest, deref_index_expr, o);
1414
1424
}
0 commit comments