File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
src/solvers/smt2_incremental
unit/solvers/smt2_incremental Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 6
6
#include < util/c_types.h>
7
7
#include < util/expr.h>
8
8
#include < util/expr_cast.h>
9
+ #include < util/expr_util.h>
9
10
#include < util/floatbv_expr.h>
10
11
#include < util/mathematical_expr.h>
11
12
#include < util/pointer_expr.h>
@@ -268,6 +269,15 @@ struct sort_based_literal_convertert : public smt_sort_const_downcast_visitort
268
269
269
270
static smt_termt convert_expr_to_smt (const constant_exprt &constant_literal)
270
271
{
272
+ if (is_null_pointer (constant_literal))
273
+ {
274
+ const size_t bit_width =
275
+ type_checked_cast<pointer_typet>(constant_literal.type ()).get_width ();
276
+ // An address of 0 encodes an object identifier of 0 for the NULL object
277
+ // and an offset of 0 into the object.
278
+ const auto address = 0 ;
279
+ return smt_bit_vector_constant_termt{address, bit_width};
280
+ }
271
281
const auto sort = convert_type_to_smt_sort (constant_literal.type ());
272
282
sort_based_literal_convertert converter (constant_literal);
273
283
sort.accept (converter);
Original file line number Diff line number Diff line change @@ -66,6 +66,24 @@ TEST_CASE(
66
66
convert_expr_to_smt (from_integer ({-1 }, signedbv_typet{16 })) ==
67
67
smt_bit_vector_constant_termt{65535 , 16 });
68
68
}
69
+ SECTION (" Null pointer" )
70
+ {
71
+ // These config lines are necessary because pointer widths depend on the
72
+ // configuration.
73
+ config.ansi_c .mode = configt::ansi_ct::flavourt::GCC;
74
+ config.ansi_c .set_arch_spec_i386 ();
75
+ const smt_termt null_pointer_term =
76
+ smt_bit_vector_constant_termt{0 , config.ansi_c .pointer_width };
77
+ CHECK (
78
+ convert_expr_to_smt (null_pointer_exprt{pointer_type (void_type ())}) ==
79
+ null_pointer_term);
80
+ CHECK (
81
+ convert_expr_to_smt (null_pointer_exprt{
82
+ pointer_type (unsignedbv_typet{100 })}) == null_pointer_term);
83
+ CHECK (
84
+ convert_expr_to_smt (null_pointer_exprt{
85
+ pointer_type (pointer_type (void_type ()))}) == null_pointer_term);
86
+ }
69
87
}
70
88
71
89
TEST_CASE (
You can’t perform that action at this time.
0 commit comments