Skip to content

Commit bf3c8ae

Browse files
authored
Merge pull request #4374 from tautschnig/nondet-test
Additional unbounded-array test that should continue to pass
2 parents ade7197 + 8bd75c8 commit bf3c8ae

File tree

5 files changed

+81
-13
lines changed

5 files changed

+81
-13
lines changed
Binary file not shown.
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
andNot_Pass.class
3+
--depth 1600 --java-unwind-enum-static --java-max-vla-length 48 --unwind 4 --max-nondet-string-length 100 --function andNot_Pass.main
4+
^\[java::andNot_Pass\.main:\(\[Ljava/lang/String;\)V.assertion\.3\] line 40 assertion at file andNot_Pass\.java line 40 function java::andNot_Pass.main:\(\[Ljava/lang/String;\)V bytecode-index 52: FAILURE$
5+
^\*\* 1 of \d+ failed
6+
VERIFICATION FAILED
7+
^EXIT=10$
8+
^SIGNAL=0$
9+
--
10+
--
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
class BitSet {
2+
boolean bits[];
3+
public BitSet()
4+
{
5+
int size = org.cprover.CProver.nondetInt();
6+
org.cprover.CProver.assume(size >= 0);
7+
bits = new boolean[size];
8+
}
9+
public void set(int i)
10+
{
11+
org.cprover.CProver.assume(i < bits.length);
12+
bits[i] = true;
13+
}
14+
public boolean get(int i)
15+
{
16+
if(i < bits.length)
17+
return bits[i];
18+
return false;
19+
}
20+
public void andNot(BitSet other)
21+
{
22+
for (int i = 0; i < bits.length; i++) {
23+
bits[i] = bits[i] && !other.get(i);
24+
}
25+
}
26+
}
27+
28+
public class andNot_Pass {
29+
public static void main(String args[]) {
30+
BitSet b1 = new BitSet();
31+
b1.set(1);
32+
b1.set(2);
33+
BitSet b2 = new BitSet();
34+
b2.set(0);
35+
b2.set(2);
36+
b1.andNot(b2);
37+
38+
assert(!b1.get(0));
39+
assert(b1.get(1));
40+
assert(b1.get(2)); // expected to fail
41+
}
42+
}

src/solvers/flattening/boolbv_index.cpp

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,40 @@ bvt boolbvt::convert_index(const index_exprt &expr)
4343
{
4444
// use array decision procedure
4545

46-
// free variables
47-
48-
bv.resize(width);
49-
for(std::size_t i=0; i<width; i++)
50-
bv[i]=prop.new_variable();
51-
5246
if(has_byte_operator(expr))
53-
record_array_index(to_index_expr(lower_byte_operators(expr, ns)));
47+
{
48+
const index_exprt final_expr =
49+
to_index_expr(lower_byte_operators(expr, ns));
50+
CHECK_RETURN(final_expr != expr);
51+
bv = convert_bv(final_expr);
52+
53+
// record type if array is a symbol
54+
const exprt &final_array = final_expr.array();
55+
if(
56+
final_array.id() == ID_symbol || final_array.id() == ID_nondet_symbol)
57+
{
58+
map.get_map_entry(final_array.get(ID_identifier), array_type);
59+
}
60+
61+
// make sure we have the index in the cache
62+
convert_bv(final_expr.index());
63+
}
5464
else
55-
record_array_index(expr);
65+
{
66+
// free variables
67+
bv.reserve(width);
68+
for(std::size_t i = 0; i < width; i++)
69+
bv.push_back(prop.new_variable());
5670

57-
// record type if array is a symbol
71+
record_array_index(expr);
5872

59-
if(array.id() == ID_symbol || array.id() == ID_nondet_symbol)
60-
map.get_map_entry(array.get(ID_identifier), array_type);
73+
// record type if array is a symbol
74+
if(array.id() == ID_symbol || array.id() == ID_nondet_symbol)
75+
map.get_map_entry(array.get(ID_identifier), array_type);
6176

62-
// make sure we have the index in the cache
63-
convert_bv(index);
77+
// make sure we have the index in the cache
78+
convert_bv(index);
79+
}
6480

6581
return bv;
6682
}

0 commit comments

Comments
 (0)