Skip to content

Commit 6844760

Browse files
authored
Merge pull request #1769 from smowton/smowton/fix/nondet-initialize-after-initialize
Java frontend: only run cproverNondetInitialize after all fields are initialized
2 parents 86a34c9 + 5669d9b commit 6844760

File tree

12 files changed

+53
-5
lines changed

12 files changed

+53
-5
lines changed
452 Bytes
Binary file not shown.
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import org.cprover.CProver;
2+
3+
class Test {
4+
5+
int[] arr;
6+
7+
void cproverNondetInitialize() {
8+
CProver.assume(arr != null && arr.length == 1);
9+
// The following access should now be legal:
10+
arr[0] = 100;
11+
}
12+
13+
public static void main(Test nondetInput) {
14+
}
15+
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CORE
2+
Test.class
3+
4+
^VERIFICATION SUCCESSFUL$
5+
174 Bytes
Binary file not shown.
729 Bytes
Binary file not shown.
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import org.cprover.CProver;
2+
3+
class Test {
4+
5+
int[] arr;
6+
7+
void cproverNondetInitialize() {
8+
CProver.assume(arr != null && arr.length == 1);
9+
// The following access should now be legal:
10+
arr[0] = 100;
11+
}
12+
13+
public static void main(Subclass nondetInput) {
14+
// The condition enforced by cproverNondetInitialize should hold
15+
// even though the parameter is a subtype of Test, not directly an
16+
// instance of Test itself.
17+
assert nondetInput.arr.length == 1;
18+
}
19+
20+
}
21+
22+
class Subclass extends Test { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CORE
2+
Test.class
3+
4+
^VERIFICATION SUCCESSFUL$
5+

src/java_bytecode/java_object_factory.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1076,16 +1076,16 @@ void java_object_factoryt::gen_nondet_struct_init(
10761076
}
10771077
}
10781078

1079-
// If <class_identifier>.cproverValidate() can be found in the
1079+
// If <class_identifier>.cproverNondetInitialize() can be found in the
10801080
// symbol table, we add a call:
10811081
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1082-
// expr.cproverValidate();
1082+
// expr.cproverNondetInitialize();
10831083
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10841084

1085-
const irep_idt validate_method_name =
1086-
"java::" + id2string(class_identifier) + ".cproverNondetInitialize:()V";
1085+
const irep_idt init_method_name =
1086+
"java::" + id2string(struct_tag) + ".cproverNondetInitialize:()V";
10871087

1088-
if(const auto func = symbol_table.lookup(validate_method_name))
1088+
if(const auto func = symbol_table.lookup(init_method_name))
10891089
{
10901090
const code_typet &type = to_code_type(func->type);
10911091
code_function_callt fun_call;

0 commit comments

Comments
 (0)