Skip to content

Commit 1cb1fd9

Browse files
author
Daniel Kroening
authored
Merge pull request #1013 from smowton/smowton/fix/array_of_zero_length
Don't warn on array_of_expr with zero length
2 parents e1c313d + 677f39d commit 1cb1fd9

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed
315 Bytes
Binary file not shown.

regression/cbmc-java/array2/test.desc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
test.class
3+
--function test.f --cover location
4+
\d+ of \d+ covered
5+
--
6+
^warning: ignoring

regression/cbmc-java/array2/test.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class test {
2+
3+
public void f(int unknown) {
4+
5+
int[] arr;
6+
if(unknown > 0)
7+
arr = new int[1];
8+
else
9+
arr = new int[0];
10+
11+
if(unknown > 0)
12+
arr[0]=1;
13+
14+
}
15+
16+
}

src/solvers/flattening/boolbv_array_of.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ bvt boolbvt::convert_array_of(const array_of_exprt &expr)
2525
std::size_t width=boolbv_width(array_type);
2626

2727
if(width==0)
28-
return conversion_failed(expr);
28+
{
29+
// A zero-length array is acceptable;
30+
// an element with unknown size is not.
31+
if(boolbv_width(array_type.subtype())==0)
32+
return conversion_failed(expr);
33+
else
34+
return bvt();
35+
}
2936

3037
const exprt &array_size=array_type.size();
3138

src/solvers/flattening/boolbv_with.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ bvt boolbvt::convert_with(const exprt &expr)
3737
std::size_t width=boolbv_width(expr.type());
3838

3939
if(width==0)
40-
return conversion_failed(expr);
40+
{
41+
// A zero-length array is acceptable:
42+
if(expr.type().id()==ID_array && boolbv_width(expr.type().subtype())!=0)
43+
return bvt();
44+
else
45+
return conversion_failed(expr);
46+
}
4147

4248
if(bv.size()!=width)
4349
{

0 commit comments

Comments
 (0)