Skip to content

Commit a1a41af

Browse files
committed
Lower byte_{extract,update} when pointers are involved
1 parent 4c37fd6 commit a1a41af

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

src/solvers/flattening/boolbv_byte_extract.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: Daniel Kroening, [email protected]
1111
#include <cassert>
1212

1313
#include <util/arith_tools.h>
14+
#include <util/expr_util.h>
1415
#include <util/std_expr.h>
1516
#include <util/byte_operators.h>
1617
#include <util/endianness_map.h>
@@ -39,8 +40,12 @@ bvt boolbvt::convert_byte_extract(const byte_extract_exprt &expr)
3940
if(expr.operands().size()!=2)
4041
throw "byte_extract takes two operands";
4142

42-
// if we extract from an unbounded array, call the flattening code
43-
if(is_unbounded_array(expr.op().type()))
43+
// if we extract from an unbounded array or a data type that
44+
// includes pointers, call the flattening code
45+
if(
46+
is_unbounded_array(expr.op().type()) ||
47+
has_subtype(expr.type(), ID_pointer, ns) ||
48+
has_subtype(expr.op().type(), ID_pointer, ns))
4449
{
4550
exprt tmp = lower_byte_extract(expr, ns);
4651
return convert_bv(tmp);

src/solvers/flattening/boolbv_byte_update.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,31 @@ Author: Daniel Kroening, [email protected]
88

99
#include "boolbv.h"
1010

11-
#include <iostream>
1211
#include <cassert>
1312

1413
#include <util/arith_tools.h>
1514
#include <util/byte_operators.h>
1615
#include <util/endianness_map.h>
16+
#include <util/expr_util.h>
17+
18+
#include <solvers/lowering/expr_lowering.h>
1719

1820
bvt boolbvt::convert_byte_update(const byte_update_exprt &expr)
1921
{
2022
if(expr.operands().size()!=3)
2123
throw "byte_update takes three operands";
2224

25+
// if we update an unbounded array or a data type that
26+
// includes pointers, call the flattening code
27+
if(
28+
is_unbounded_array(expr.op().type()) ||
29+
has_subtype(expr.value().type(), ID_pointer, ns) ||
30+
has_subtype(expr.op0().type(), ID_pointer, ns))
31+
{
32+
exprt tmp = lower_byte_update(expr, ns);
33+
return convert_bv(tmp);
34+
}
35+
2336
const exprt &op=expr.op0();
2437
const exprt &offset_expr=expr.offset();
2538
const exprt &value=expr.value();

src/solvers/lowering/byte_operators.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -875,9 +875,7 @@ static exprt lower_byte_update(
875875
}
876876
}
877877

878-
static exprt lower_byte_update(
879-
const byte_update_exprt &src,
880-
const namespacet &ns)
878+
exprt lower_byte_update(const byte_update_exprt &src, const namespacet &ns)
881879
{
882880
return lower_byte_update(src, ns, false);
883881
}

src/solvers/lowering/expr_lowering.h

+3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ Author: Michael Tautschnig
1212
#include <util/expr.h>
1313

1414
class byte_extract_exprt;
15+
class byte_update_exprt;
1516
class namespacet;
1617
class popcount_exprt;
1718

1819
exprt lower_byte_extract(const byte_extract_exprt &src, const namespacet &ns);
1920

21+
exprt lower_byte_update(const byte_update_exprt &src, const namespacet &ns);
22+
2023
exprt lower_byte_operators(const exprt &src, const namespacet &ns);
2124

2225
bool has_byte_operator(const exprt &src);

0 commit comments

Comments
 (0)