Skip to content

Commit bec782e

Browse files
Merge pull request diffblue#5112 from romainbrenguier/feature/assign-from-json-ref
[TG-9450] Allocate reference arrays with constant size in assignments from json
2 parents 85d5e13 + bc47e49 commit bec782e

16 files changed

+716
-170
lines changed
Binary file not shown.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class Util {
2+
public static char[] chars(int count) {
3+
char result[] = new char[count];
4+
for (int i = 0; i < count; ++i) {
5+
result[i] = (char)((int)'a' + i);
6+
}
7+
return result;
8+
}
9+
}
10+
11+
public class Test {
12+
// static field which is initialized to a non-empty value
13+
public static char[] staticCharArray = Util.chars(26);
14+
// reference to the same array
15+
public static char[] staticCharArrayRef = staticCharArray;
16+
17+
public static char[] charArray() {
18+
staticCharArray[0] = staticCharArray[3];
19+
staticCharArray[1] = 'e';
20+
assert staticCharArray[0] == 'd';
21+
assert staticCharArray[0] == 'A';
22+
return staticCharArray;
23+
}
24+
25+
public static char[] charArrayRef() {
26+
staticCharArrayRef[0] = staticCharArray[3];
27+
staticCharArray[1] = 'e';
28+
if (staticCharArray[0] == 'A') {
29+
assert false;
30+
} else if (staticCharArray[0] == 'd') {
31+
assert false;
32+
}
33+
34+
return staticCharArray;
35+
}
36+
}
Binary file not shown.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"@type":"com.diffblue.retriever.StaticFieldMap",
3+
"Test":{
4+
"@type":"com.diffblue.retriever.StaticFieldMap",
5+
"staticCharArrayRef":{
6+
"@type":"[C",
7+
"@ref": "id1"
8+
},
9+
"staticCharArray":{
10+
"@type":"[C",
11+
"@id": "id1",
12+
"@items":[
13+
"abcAefghijklmnopqrstuvwxyz"
14+
]
15+
}
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
Test.class
3+
--function Test.charArrayRef --property "java::Test.charArrayRef:()[C.assertion.2" --static-values static-values.json
4+
Generated 0 VCC[(]s[)], 0 remaining after simplification
5+
assertion at file Test.java line 31 .*: SUCCESS
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
9+
--
10+
Not that the json file has been modified on purpose so that this checks
11+
that it is actually loaded and not retrieved by execution of the Util function.
12+
This test does not work with symex-driven-lazy-loading because this option is
13+
not compatible with --property.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
Test.class
3+
--function Test.charArrayRef --property "java::Test.charArrayRef:()[C.assertion.1"
4+
Generated 0 VCC[(]s[)], 0 remaining after simplification
5+
assertion at file Test.java line 29 .*: SUCCESS
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
9+
--
10+
Note that the json file has been modified on purpose so that this checks
11+
that it is actually loaded and not retrieved by execution of the Util function.
12+
This test does not work with symex-driven-lazy-loading because this option is
13+
not compatible with --property.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
Test.class
3+
--function Test.charArray --property "java::Test.charArray:()[C.assertion.2" --static-values static-values.json
4+
Generated 0 VCC[(]s[)], 0 remaining after simplification
5+
assertion at file Test.java line 21 .*: SUCCESS
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
9+
--
10+
Note that the json file has been modified on purpose so that this checks
11+
that it is actually loaded and not retrieved by execution of the Util function.
12+
This test does not work with symex-driven-lazy-loading because this option is
13+
not compatible with --property.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
Test.class
3+
--function Test.charArray --property "java::Test.charArray:()[C.assertion.1"
4+
Generated 0 VCC[(]s[)], 0 remaining after simplification
5+
assertion at file Test.java line 20 .*: SUCCESS
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
9+
--
10+
Checks that constant propagation happens through static arrays.
11+
This test does not work with symex-driven-lazy-loading because this option is
12+
not compatible with --property.

jbmc/src/java_bytecode/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ SRC = assignments_from_json.cpp \
33
character_refine_preprocess.cpp \
44
ci_lazy_methods.cpp \
55
ci_lazy_methods_needed.cpp \
6+
code_with_references.cpp \
67
convert_java_nondet.cpp \
78
create_array_with_type_intrinsic.cpp \
89
expr2java.cpp \

0 commit comments

Comments
 (0)