Skip to content

Commit f71edea

Browse files
authored
Merge pull request #7297 from diffblue/union-large-array
performance improvement for large bitvectors
2 parents 63da579 + 1e890a5 commit f71edea

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

regression/cbmc/bounds_check1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE broken-z3-smt-backend
22
main.c
33
--bounds-check --pointer-check
44
^EXIT=10$
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#define LARGE 100000
2+
3+
// This is to test the efficiency of unions that contain a large array.
4+
union U
5+
{
6+
char large_array[LARGE];
7+
int something_else;
8+
};
9+
10+
int main()
11+
{
12+
union U u;
13+
u.something_else = 1234;
14+
__CPROVER_assert(0, "should fail");
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE broken-z3-smt-backend
2+
union_large_array.c
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^\[main\.assertion\.1\] line \d+ should fail: FAILURE$
7+
^\*\* 1 of 1 failed
8+
^VERIFICATION FAILED$
9+
--
10+
^warning: ignoring
11+
--

src/solvers/flattening/boolbv_get.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ exprt boolbvt::bv_get_rec(const exprt &expr, const bvt &bv, std::size_t offset)
199199
const std::size_t width = boolbv_width(type);
200200
PRECONDITION(bv.size() >= offset + width);
201201

202-
// most significant bit first
203202
std::string value;
203+
value.reserve(width);
204204

205205
for(std::size_t bit_nr=offset; bit_nr<offset+width; bit_nr++)
206206
{
@@ -214,9 +214,13 @@ exprt boolbvt::bv_get_rec(const exprt &expr, const bvt &bv, std::size_t offset)
214214
}
215215
// clang-format on
216216

217-
value=ch+value;
217+
value += ch;
218218
}
219219

220+
// The above collects bits starting with the least significant bit,
221+
// but we need the most significant bit first.
222+
std::reverse(value.begin(), value.end());
223+
220224
switch(bvtype)
221225
{
222226
case bvtypet::IS_UNKNOWN:

0 commit comments

Comments
 (0)