Skip to content

Commit fba1372

Browse files
authored
Merge 9530cd3 into 308cc0a
2 parents 308cc0a + 9530cd3 commit fba1372

File tree

7 files changed

+95
-74
lines changed

7 files changed

+95
-74
lines changed

scripts/expected_doxygen_warnings.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@
8282
warning: Include graph for 'goto_instrument_parse_options.cpp' not generated, too many nodes (97), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
8383
warning: Included by graph for 'goto_functions.h' not generated, too many nodes (66), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
8484
warning: Included by graph for 'goto_model.h' not generated, too many nodes (110), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
85-
warning: Included by graph for 'arith_tools.h' not generated, too many nodes (181), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
85+
warning: Included by graph for 'arith_tools.h' not generated, too many nodes (180), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
8686
warning: Included by graph for 'c_types.h' not generated, too many nodes (110), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
87-
warning: Included by graph for 'config.h' not generated, too many nodes (85), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
87+
warning: Included by graph for 'config.h' not generated, too many nodes (84), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
8888
warning: Included by graph for 'exception_utils.h' not generated, too many nodes (61), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
8989
warning: Included by graph for 'expr.h' not generated, too many nodes (87), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
9090
warning: Included by graph for 'expr_util.h' not generated, too many nodes (61), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.

src/solvers/flattening/boolbv.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include <util/arith_tools.h>
1616
#include <util/bitvector_expr.h>
17+
#include <util/config.h>
1718
#include <util/floatbv_expr.h>
1819
#include <util/magic.h>
1920
#include <util/mp_arith.h>
@@ -31,6 +32,13 @@ Author: Daniel Kroening, [email protected]
3132
#include <solvers/floatbv/float_utils.h>
3233
#include <solvers/lowering/expr_lowering.h>
3334

35+
endianness_mapt boolbvt::endianness_map(const typet &type) const
36+
{
37+
const bool little_endian =
38+
config.ansi_c.endianness == configt::ansi_ct::endiannesst::IS_LITTLE_ENDIAN;
39+
return endianness_map(type, little_endian);
40+
}
41+
3442
/// Convert expression to vector of literalts, using an internal
3543
/// cache to speed up conversion if available. Also assert the resultant
3644
/// vector is of a specific size, and freeze any elements if appropriate.

src/solvers/flattening/boolbv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class boolbvt:public arrayst
104104
return endianness_mapt{type, little_endian, ns};
105105
}
106106

107+
virtual endianness_mapt endianness_map(const typet &type) const;
108+
107109
protected:
108110
boolbv_widtht bv_width;
109111
bv_utilst bv_utils;

src/solvers/flattening/boolbv_byte_update.cpp

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,31 +58,23 @@ bvt boolbvt::convert_byte_update(const byte_update_exprt &expr)
5858
}
5959
else
6060
{
61-
if(little_endian)
62-
{
63-
for(std::size_t i=0; i<update_width; i++)
64-
bv[numeric_cast_v<std::size_t>(offset + i)] = value_bv[i];
65-
}
66-
else
67-
{
68-
endianness_mapt map_op = endianness_map(op.type(), false);
69-
endianness_mapt map_value = endianness_map(value.type(), false);
61+
endianness_mapt map_op = endianness_map(op.type(), little_endian);
62+
endianness_mapt map_value = endianness_map(value.type(), little_endian);
7063

71-
const std::size_t offset_i = numeric_cast_v<std::size_t>(offset);
64+
const std::size_t offset_i = numeric_cast_v<std::size_t>(offset);
7265

73-
for(std::size_t i=0; i<update_width; i++)
74-
{
75-
size_t index_op=map_op.map_bit(offset_i+i);
76-
size_t index_value=map_value.map_bit(i);
66+
for(std::size_t i = 0; i < update_width; i++)
67+
{
68+
size_t index_op = map_op.map_bit(offset_i + i);
69+
size_t index_value = map_value.map_bit(i);
7770

78-
INVARIANT(
79-
index_op < bv.size(), "bit vector index shall be within bounds");
80-
INVARIANT(
81-
index_value < value_bv.size(),
82-
"bit vector index shall be within bounds");
71+
INVARIANT(
72+
index_op < bv.size(), "bit vector index shall be within bounds");
73+
INVARIANT(
74+
index_value < value_bv.size(),
75+
"bit vector index shall be within bounds");
8376

84-
bv[index_op]=value_bv[index_value];
85-
}
77+
bv[index_op] = value_bv[index_value];
8678
}
8779
}
8880

src/solvers/flattening/boolbv_member.cpp

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ Author: Daniel Kroening, [email protected]
88

99
#include "boolbv.h"
1010

11-
bvt boolbvt::convert_member(const member_exprt &expr)
11+
static bvt convert_member_struct(
12+
const member_exprt &expr,
13+
const bvt &struct_bv,
14+
const std::function<std::size_t(const typet &)> boolbv_width,
15+
const namespacet &ns)
1216
{
1317
const exprt &struct_op=expr.struct_op();
1418
const typet &struct_op_type=ns.follow(struct_op.type());
1519

16-
const bvt &struct_bv=convert_bv(struct_op);
17-
1820
const irep_idt &component_name = expr.get_component_name();
19-
const struct_union_typet::componentst &components =
20-
to_struct_union_type(struct_op_type).components();
21+
const struct_typet::componentst &components =
22+
to_struct_type(struct_op_type).components();
2123

2224
std::size_t offset = 0;
2325

@@ -42,8 +44,7 @@ bvt boolbvt::convert_member(const member_exprt &expr)
4244
struct_bv.begin() + offset, struct_bv.begin() + offset + sub_width);
4345
}
4446

45-
if(struct_op_type.id() != ID_union)
46-
offset += sub_width;
47+
offset += sub_width;
4748
}
4849

4950
INVARIANT_WITH_DIAGNOSTICS(
@@ -52,3 +53,52 @@ bvt boolbvt::convert_member(const member_exprt &expr)
5253
expr.find_source_location(),
5354
id2string(component_name));
5455
}
56+
57+
static bvt convert_member_union(
58+
const member_exprt &expr,
59+
const bvt &union_bv,
60+
const boolbvt &boolbv,
61+
const namespacet &ns)
62+
{
63+
const exprt &union_op = expr.compound();
64+
const union_typet &union_op_type =
65+
ns.follow_tag(to_union_tag_type(union_op.type()));
66+
67+
const irep_idt &component_name = expr.get_component_name();
68+
const union_typet::componentt &component =
69+
union_op_type.get_component(component_name);
70+
DATA_INVARIANT_WITH_DIAGNOSTICS(
71+
component.is_not_nil(),
72+
"union type shall contain component accessed by member expression",
73+
expr.find_source_location(),
74+
id2string(component_name));
75+
76+
const typet &subtype = component.type();
77+
const std::size_t sub_width = boolbv.boolbv_width(subtype);
78+
79+
endianness_mapt map_u = boolbv.endianness_map(union_op_type);
80+
endianness_mapt map_component = boolbv.endianness_map(subtype);
81+
82+
bvt result(sub_width, literalt{});
83+
for(std::size_t i = 0; i < sub_width; ++i)
84+
result[map_u.map_bit(i)] = union_bv[map_component.map_bit(i)];
85+
86+
return result;
87+
}
88+
89+
bvt boolbvt::convert_member(const member_exprt &expr)
90+
{
91+
const bvt &compound_bv = convert_bv(expr.compound());
92+
93+
if(expr.compound().type().id() == ID_struct_tag)
94+
return convert_member_struct(
95+
expr,
96+
compound_bv,
97+
[this](const typet &t) { return boolbv_width(t); },
98+
ns);
99+
else
100+
{
101+
PRECONDITION(expr.compound().type().id() == ID_union_tag);
102+
return convert_member_union(expr, compound_bv, *this, ns);
103+
}
104+
}

src/solvers/flattening/boolbv_union.cpp

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ Author: Daniel Kroening, [email protected]
88

99
#include "boolbv.h"
1010

11-
#include <util/arith_tools.h>
12-
#include <util/config.h>
13-
1411
bvt boolbvt::convert_union(const union_exprt &expr)
1512
{
1613
std::size_t width=boolbv_width(expr.type());
@@ -28,31 +25,15 @@ bvt boolbvt::convert_union(const union_exprt &expr)
2825
bvt bv;
2926
bv.resize(width);
3027

31-
if(config.ansi_c.endianness==configt::ansi_ct::endiannesst::IS_LITTLE_ENDIAN)
32-
{
33-
for(std::size_t i=0; i<op_bv.size(); i++)
34-
bv[i]=op_bv[i];
35-
36-
// pad with nondets
37-
for(std::size_t i=op_bv.size(); i<bv.size(); i++)
38-
bv[i]=prop.new_variable();
39-
}
40-
else
41-
{
42-
INVARIANT(
43-
config.ansi_c.endianness == configt::ansi_ct::endiannesst::IS_BIG_ENDIAN,
44-
"endianness should be set to either little endian or big endian");
45-
46-
endianness_mapt map_u = endianness_map(expr.type(), false);
47-
endianness_mapt map_op = endianness_map(expr.op().type(), false);
48-
49-
for(std::size_t i=0; i<op_bv.size(); i++)
50-
bv[map_u.map_bit(i)]=op_bv[map_op.map_bit(i)];
51-
52-
// pad with nondets
53-
for(std::size_t i=op_bv.size(); i<bv.size(); i++)
54-
bv[map_u.map_bit(i)]=prop.new_variable();
55-
}
28+
endianness_mapt map_u = endianness_map(expr.type());
29+
endianness_mapt map_op = endianness_map(expr.op().type());
30+
31+
for(std::size_t i = 0; i < op_bv.size(); i++)
32+
bv[map_u.map_bit(i)] = op_bv[map_op.map_bit(i)];
33+
34+
// pad with nondets
35+
for(std::size_t i = op_bv.size(); i < bv.size(); i++)
36+
bv[map_u.map_bit(i)] = prop.new_variable();
5637

5738
return bv;
5839
}

src/solvers/flattening/boolbv_with.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Author: Daniel Kroening, [email protected]
1111
#include <util/std_types.h>
1212
#include <util/std_expr.h>
1313
#include <util/arith_tools.h>
14-
#include <util/config.h>
1514

1615
bvt boolbvt::convert_with(const with_exprt &expr)
1716
{
@@ -236,20 +235,9 @@ void boolbvt::convert_with_union(
236235
"convert_with_union: unexpected operand op2 width",
237236
irep_pretty_diagnosticst{type});
238237

239-
if(config.ansi_c.endianness==configt::ansi_ct::endiannesst::IS_LITTLE_ENDIAN)
240-
{
241-
for(std::size_t i=0; i<op2_bv.size(); i++)
242-
next_bv[i]=op2_bv[i];
243-
}
244-
else
245-
{
246-
assert(
247-
config.ansi_c.endianness==configt::ansi_ct::endiannesst::IS_BIG_ENDIAN);
238+
endianness_mapt map_u = endianness_map(type);
239+
endianness_mapt map_op2 = endianness_map(op2.type());
248240

249-
endianness_mapt map_u = endianness_map(type, false);
250-
endianness_mapt map_op2 = endianness_map(op2.type(), false);
251-
252-
for(std::size_t i=0; i<op2_bv.size(); i++)
253-
next_bv[map_u.map_bit(i)]=op2_bv[map_op2.map_bit(i)];
254-
}
241+
for(std::size_t i = 0; i < op2_bv.size(); i++)
242+
next_bv[map_u.map_bit(i)] = op2_bv[map_op2.map_bit(i)];
255243
}

0 commit comments

Comments
 (0)