@@ -136,34 +136,28 @@ void smt2_convt::define_object_size(
136
136
const exprt &expr)
137
137
{
138
138
assert (expr.id ()==ID_object_size);
139
- const exprt &ptr = expr.op0 ();
140
- std::size_t size_width = boolbv_width (expr.type ());
141
- std::size_t pointer_width = boolbv_width (ptr.type ());
142
- std::size_t number = 0 ;
143
- std::size_t h=pointer_width-1 ;
144
- std::size_t l=pointer_width-config.bv_encoding .object_bits ;
139
+ const exprt &ptr=expr.op0 ();
140
+ std::size_t size_width=boolbv_width (expr.type ());
141
+ std::size_t number=0 ;
142
+ std::size_t object_bits=pointer_logic.get_object_width ();
145
143
146
144
for (const auto &o : pointer_logic.objects )
147
145
{
148
- const typet &type = ns.follow (o.type ());
149
- exprt size_expr = size_of_expr (type, ns);
150
- mp_integer object_size;
146
+ const typet &type=ns.follow (o.type ());
147
+ mp_integer object_size=pointer_offset_size (type, ns);
151
148
152
- if (o.id ()!=ID_symbol ||
153
- size_expr.is_nil () ||
154
- to_integer (size_expr, object_size))
149
+ if (o.id ()!=ID_symbol || object_size<=0 )
155
150
{
156
151
++number;
157
152
continue ;
158
153
}
159
154
160
155
out << " (assert (implies (= " <<
161
- " ((_ extract " << h << " " << l << " ) " ;
156
+ " ((_ extract " << object_bits- 1 << " 0 ) " ;
162
157
convert_expr (ptr);
163
- out << " ) (_ bv" << number << " "
164
- << config.bv_encoding .object_bits << " ))"
165
- << " (= " << id << " (_ bv" << object_size.to_ulong () << " "
166
- << size_width << " ))))\n " ;
158
+ out << " ) (_ bv" << number << " " << object_bits << " ))" <<
159
+ " (= " << id << " (_ bv" << object_size.to_ulong () << " " <<
160
+ size_width << " ))))\n " ;
167
161
168
162
++number;
169
163
}
@@ -474,10 +468,12 @@ exprt smt2_convt::parse_rec(const irept &src, const typet &_type)
474
468
to_integer (bv_expr, v);
475
469
476
470
// split into object and offset
477
- mp_integer pow=power (2 , width-config.bv_encoding .object_bits );
471
+ std::size_t object_bits=pointer_logic.get_object_width ();
472
+ std::size_t offset_bits=pointer_logic.get_offset_width ();
473
+ mp_integer pow=power (2 , object_bits);
478
474
pointer_logict::pointert ptr;
479
- ptr.object =integer2size_t (v/ pow);
480
- ptr.offset =v% pow;
475
+ ptr.object =integer2size_t (v% pow);
476
+ ptr.offset =(v% power ( 2 , object_bits+offset_bits))/ pow;
481
477
return pointer_logic.pointer_expr (ptr, to_pointer_type (type));
482
478
}
483
479
else if (type.id ()==ID_struct)
@@ -505,12 +501,18 @@ void smt2_convt::convert_address_of_rec(
505
501
expr.id ()==ID_string_constant ||
506
502
expr.id ()==ID_label)
507
503
{
504
+ std::string addr=
505
+ expr.id ()==ID_symbol?
506
+ expr.get_string (ID_identifier)+" $address" :
507
+ " (_ bv0 " +std::to_string (pointer_logic.get_address_width ())+" )" ;
508
+
508
509
out
509
- << " (concat (_ bv"
510
- << pointer_logic.add_object (expr) << " "
511
- << config.bv_encoding .object_bits << " )"
512
- << " (_ bv0 "
513
- << boolbv_width (result_type)-config.bv_encoding .object_bits << " ))" ;
510
+ << " (concat "
511
+ << " (concat "
512
+ << " (_ bv" << pointer_logic.add_object (expr)
513
+ << " " << pointer_logic.get_object_width () << " ) "
514
+ << " (_ bv0 " << pointer_logic.get_offset_width () << " )) "
515
+ << addr << " )" ;
514
516
}
515
517
else if (expr.id ()==ID_index)
516
518
{
@@ -1329,38 +1331,32 @@ void smt2_convt::convert_expr(const exprt &expr)
1329
1331
{
1330
1332
assert (expr.operands ().size ()==1 );
1331
1333
assert (expr.op0 ().type ().id ()==ID_pointer);
1332
- std::size_t offset_bits=
1333
- boolbv_width (expr. op0 (). type ())-config. bv_encoding . object_bits ;
1334
- std::size_t result_width =boolbv_width (expr.type ());
1334
+ std::size_t object_bits=pointer_logic. get_object_width ();
1335
+ std:: size_t offset_bits=pointer_logic. get_offset_width () ;
1336
+ std::size_t ext =boolbv_width (expr.type ())-offset_bits ;
1335
1337
1336
- // max extract width
1337
- if (offset_bits>result_width)
1338
- offset_bits=result_width;
1339
-
1340
- // too few bits?
1341
- if (result_width>offset_bits)
1342
- out << " ((_ zero_extend " << result_width-offset_bits << " ) " ;
1338
+ if (ext>0 )
1339
+ out << " ((_ zero_extend " << ext << " ) " ;
1343
1340
1344
- out << " ((_ extract " << offset_bits-1 << " 0) " ;
1341
+ out << " ((_ extract " << object_bits+offset_bits-1
1342
+ << " " << object_bits << " ) " ;
1345
1343
convert_expr (expr.op0 ());
1346
1344
out << " )" ;
1347
1345
1348
- if (result_width>offset_bits )
1346
+ if (ext> 0 )
1349
1347
out << " )" ; // zero_extend
1350
1348
}
1351
1349
else if (expr.id ()==ID_pointer_object)
1352
1350
{
1353
1351
assert (expr.operands ().size ()==1 );
1354
1352
assert (expr.op0 ().type ().id ()==ID_pointer);
1355
- std::size_t ext= boolbv_width (expr. type ())-config. bv_encoding . object_bits ;
1356
- std::size_t pointer_width =boolbv_width (expr.op0 (). type ());
1353
+ std::size_t object_bits=pointer_logic. get_object_width () ;
1354
+ std::size_t ext =boolbv_width (expr.type ())-object_bits ;
1357
1355
1358
1356
if (ext>0 )
1359
1357
out << " ((_ zero_extend " << ext << " ) " ;
1360
1358
1361
- out << " ((_ extract "
1362
- << pointer_width-1 << " "
1363
- << pointer_width-config.bv_encoding .object_bits << " ) " ;
1359
+ out << " ((_ extract " << object_bits-1 << " 0) " ;
1364
1360
convert_expr (expr.op0 ());
1365
1361
out << " )" ;
1366
1362
@@ -1374,14 +1370,12 @@ void smt2_convt::convert_expr(const exprt &expr)
1374
1370
else if (expr.id ()==ID_invalid_pointer)
1375
1371
{
1376
1372
assert (expr.operands ().size ()==1 );
1373
+ std::size_t object_bits=pointer_logic.get_object_width ();
1377
1374
1378
- std::size_t pointer_width=boolbv_width (expr.op0 ().type ());
1379
- out << " (= ((_ extract "
1380
- << pointer_width-1 << " "
1381
- << pointer_width-config.bv_encoding .object_bits << " ) " ;
1375
+ out << " (= ((_ extract " << object_bits-1 << " 0) " ;
1382
1376
convert_expr (expr.op0 ());
1383
1377
out << " ) (_ bv" << pointer_logic.get_invalid_object ()
1384
- << " " << config. bv_encoding . object_bits << " ))" ;
1378
+ << " " << object_bits << " ))" ;
1385
1379
}
1386
1380
else if (expr.id ()==" pointer_object_has_type" )
1387
1381
{
@@ -2751,31 +2745,28 @@ void smt2_convt::convert_is_dynamic_object(const exprt &expr)
2751
2745
pointer_logic.get_dynamic_objects (dynamic_objects);
2752
2746
2753
2747
assert (expr.operands ().size ()==1 );
2748
+ std::size_t object_bits=pointer_logic.get_object_width ();
2754
2749
2755
2750
if (dynamic_objects.empty ())
2756
2751
out << " false" ;
2757
2752
else
2758
2753
{
2759
- std::size_t pointer_width=boolbv_width (expr.op0 ().type ());
2760
-
2761
- out << " (let ((?obj ((_ extract "
2762
- << pointer_width-1 << " "
2763
- << pointer_width-config.bv_encoding .object_bits << " ) " ;
2754
+ out << " (let ((?obj ((_ extract " << object_bits << " 0) " ;
2764
2755
convert_expr (expr.op0 ());
2765
2756
out << " ))) " ;
2766
2757
2767
2758
if (dynamic_objects.size ()==1 )
2768
2759
{
2769
2760
out << " (= (_ bv" << dynamic_objects.front ()
2770
- << " " << config. bv_encoding . object_bits << " ) ?obj)" ;
2761
+ << " " << object_bits << " ) ?obj)" ;
2771
2762
}
2772
2763
else
2773
2764
{
2774
2765
out << " (or" ;
2775
2766
2776
2767
for (const auto &object : dynamic_objects)
2777
2768
out << " (= (_ bv" << object
2778
- << " " << config. bv_encoding . object_bits << " ) ?obj)" ;
2769
+ << " " << object_bits << " ) ?obj)" ;
2779
2770
2780
2771
out << " )" ; // or
2781
2772
}
0 commit comments