Skip to content

Commit 68cbf7a

Browse files
authored
Merge pull request diffblue#6861 from tautschnig/cleanup/use-get_member
Use boolbv_width::get_member
2 parents 8303a79 + 58f3053 commit 68cbf7a

File tree

2 files changed

+19
-58
lines changed

2 files changed

+19
-58
lines changed

src/solvers/flattening/boolbv_member.cpp

Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,6 @@ Author: Daniel Kroening, [email protected]
1111
#include <util/c_types.h>
1212
#include <util/namespace.h>
1313

14-
static bvt convert_member_struct(
15-
const member_exprt &expr,
16-
const bvt &struct_bv,
17-
const std::function<std::size_t(const typet &)> boolbv_width,
18-
const namespacet &ns)
19-
{
20-
const exprt &struct_op=expr.struct_op();
21-
const typet &struct_op_type=ns.follow(struct_op.type());
22-
23-
const irep_idt &component_name = expr.get_component_name();
24-
const struct_typet::componentst &components =
25-
to_struct_type(struct_op_type).components();
26-
27-
std::size_t offset = 0;
28-
29-
for(const auto &c : components)
30-
{
31-
const typet &subtype = c.type();
32-
const std::size_t sub_width = boolbv_width(subtype);
33-
34-
if(c.get_name() == component_name)
35-
{
36-
DATA_INVARIANT_WITH_DIAGNOSTICS(
37-
subtype == expr.type(),
38-
"component type shall match the member expression type",
39-
subtype.pretty(),
40-
expr.type().pretty());
41-
INVARIANT(
42-
offset + sub_width <= struct_bv.size(),
43-
"bitvector part corresponding to element shall be contained within the "
44-
"full aggregate bitvector");
45-
46-
return bvt(
47-
struct_bv.begin() + offset, struct_bv.begin() + offset + sub_width);
48-
}
49-
50-
offset += sub_width;
51-
}
52-
53-
INVARIANT_WITH_DIAGNOSTICS(
54-
false,
55-
"struct type shall contain component accessed by member expression",
56-
expr.find_source_location(),
57-
id2string(component_name));
58-
}
59-
6014
static bvt convert_member_union(
6115
const member_exprt &expr,
6216
const bvt &union_bv,
@@ -94,11 +48,22 @@ bvt boolbvt::convert_member(const member_exprt &expr)
9448
const bvt &compound_bv = convert_bv(expr.compound());
9549

9650
if(expr.compound().type().id() == ID_struct_tag)
97-
return convert_member_struct(
98-
expr,
99-
compound_bv,
100-
[this](const typet &t) { return boolbv_width(t); },
101-
ns);
51+
{
52+
const struct_typet &struct_op_type =
53+
ns.follow_tag(to_struct_tag_type(expr.compound().type()));
54+
55+
const auto &member_bits =
56+
bv_width.get_member(struct_op_type, expr.get_component_name());
57+
58+
INVARIANT(
59+
member_bits.offset + member_bits.width <= compound_bv.size(),
60+
"bitvector part corresponding to element shall be contained within the "
61+
"full aggregate bitvector");
62+
63+
return bvt(
64+
compound_bv.begin() + member_bits.offset,
65+
compound_bv.begin() + member_bits.offset + member_bits.width);
66+
}
10267
else
10368
{
10469
PRECONDITION(expr.compound().type().id() == ID_union_tag);

src/solvers/smt2/smt2_conv.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4226,14 +4226,10 @@ void smt2_convt::convert_member(const member_exprt &expr)
42264226
else
42274227
{
42284228
// we extract
4229-
const std::size_t member_width = boolbv_width(expr.type());
4230-
const auto member_offset = member_offset_bits(struct_type, name, ns);
4229+
const auto member_offset = boolbv_width.get_member(struct_type, name);
42314230

4232-
CHECK_RETURN_WITH_DIAGNOSTICS(
4233-
member_offset.has_value(), "failed to get struct member offset");
4234-
4235-
out << "((_ extract " << (member_offset.value() + member_width - 1) << " "
4236-
<< member_offset.value() << ") ";
4231+
out << "((_ extract " << (member_offset.offset + member_offset.width - 1)
4232+
<< " " << member_offset.offset << ") ";
42374233
convert_expr(struct_op);
42384234
out << ")";
42394235
}

0 commit comments

Comments
 (0)