forked from diffblue/cbmc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java: run nondet-initialize method *after* initialization
Previously this method was run after each supertype of a relevant type was initialised, e.g. if MyClass <: MySupertype <: Object, then MyClass.cproverNondetInitialize would get run after my inner Object was set up, then again after MySupertype was set up, then one more time after the whole class was set up. Now it will only run after the whole initialisation is complete. This fixes a bug where array members could have inconsistent length and data field values because they had not been initialised yet, leading to an assertion failure during nondetInitialize, and also has the desirable side-effect that an initialiser will still be run when creating a subtype.
- Loading branch information
Showing
8 changed files
with
53 additions
and
5 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import org.cprover.CProver; | ||
|
||
class Test { | ||
|
||
int[] arr; | ||
|
||
void cproverNondetInitialize() { | ||
CProver.assume(arr != null && arr.length == 1); | ||
// The following access should now be legal: | ||
arr[0] = 100; | ||
} | ||
|
||
public static void main(Test nondetInput) { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CORE | ||
Test.class | ||
|
||
^VERIFICATION SUCCESSFUL$ | ||
|
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import org.cprover.CProver; | ||
|
||
class Test { | ||
|
||
int[] arr; | ||
|
||
void cproverNondetInitialize() { | ||
CProver.assume(arr != null && arr.length == 1); | ||
// The following access should now be legal: | ||
arr[0] = 100; | ||
} | ||
|
||
public static void main(Subclass nondetInput) { | ||
// The condition enforced by cproverNondetInitialize should hold | ||
// even though the parameter is a subtype of Test, not directly an | ||
// instance of Test itself. | ||
assert nondetInput.arr.length == 1; | ||
} | ||
|
||
} | ||
|
||
class Subclass extends Test { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CORE | ||
Test.class | ||
|
||
^VERIFICATION SUCCESSFUL$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters