-
Notifications
You must be signed in to change notification settings - Fork 274
Supports nested quantifiers in function contracts #5968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SaswatPadhi
merged 1 commit into
diffblue:develop
from
ArenBabikian:contracts-quantifiers-nested
Apr 9, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,24 @@ | ||
// clang-format off | ||
int f1(int *arr) __CPROVER_ensures(__CPROVER_forall { | ||
int i; | ||
__CPROVER_forall | ||
{ | ||
int j; | ||
(0 <= i && i < 10 && i <= j && j < 10) ==> arr[i] <= arr[j] | ||
} | ||
}) | ||
// clang-format on | ||
{ | ||
for(int i = 0; i < 10; i++) | ||
{ | ||
arr[i] = i; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int main() | ||
{ | ||
int arr[10]; | ||
f1(arr); | ||
} |
This file contains hidden or 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,11 @@ | ||
CORE | ||
main.c | ||
--enforce-all-contracts | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
Verification: | ||
This test case checks the handling of a forall expression | ||
nested within another forall expression. |
This file contains hidden or 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,19 @@ | ||
// clang-format off | ||
int f1(int *arr) __CPROVER_requires(__CPROVER_forall { | ||
int i; | ||
0 <= i && i < 9 ==> __CPROVER_forall | ||
{ | ||
int j; | ||
(i <= j && j < 10) ==> arr[i] <= arr[j] | ||
} | ||
}) __CPROVER_ensures(__CPROVER_return_value == 0) | ||
// clang-format on | ||
{ | ||
return 0; | ||
} | ||
|
||
int main() | ||
{ | ||
int arr[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | ||
f1(arr); | ||
} |
This file contains hidden or 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,11 @@ | ||
CORE | ||
main.c | ||
--replace-all-calls-with-contracts | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
Verification: | ||
This test case checks the handling of a forall expression | ||
nested within an implication. |
This file contains hidden or 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,19 @@ | ||
int f1(int *arr) | ||
__CPROVER_ensures(__CPROVER_return_value == 0 && __CPROVER_exists { | ||
int i; | ||
(0 <= i && i < 10) && arr[i] == i | ||
}) | ||
{ | ||
for(int i = 0; i < 10; i++) | ||
{ | ||
arr[i] = i; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int main() | ||
{ | ||
int arr[10]; | ||
f1(arr); | ||
} |
This file contains hidden or 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,11 @@ | ||
CORE | ||
main.c | ||
--enforce-all-contracts | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
Verification: | ||
This test case checks the handling of an exists expression | ||
nested within a conjunction. |
This file contains hidden or 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,21 @@ | ||
// clang-format off | ||
int f1(int *arr) __CPROVER_requires( | ||
__CPROVER_forall { | ||
int i; | ||
(0 <= i && i < 10) ==> arr[i] == 0 | ||
} || | ||
arr[9] == -1 || | ||
__CPROVER_exists { | ||
int i; | ||
(0 <= i && i < 10) && arr[i] == i | ||
}) __CPROVER_ensures(__CPROVER_return_value == 0) | ||
// clang-format on | ||
{ | ||
return 0; | ||
} | ||
|
||
int main() | ||
{ | ||
int arr[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | ||
f1(arr); | ||
} |
This file contains hidden or 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,11 @@ | ||
CORE | ||
main.c | ||
--replace-all-calls-with-contracts | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
Verification: | ||
This test case checks the handling of both a forall expression | ||
and an exists expression nested within a disjunction. |
This file contains hidden or 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,15 @@ | ||
// clang-format off | ||
int f1(int *arr) __CPROVER_requires(!__CPROVER_forall { | ||
int i; | ||
(0 <= i && i < 10) ==> arr[i] == 0 | ||
}) __CPROVER_ensures(__CPROVER_return_value == 0) | ||
// clang-format on | ||
{ | ||
return 0; | ||
} | ||
|
||
int main() | ||
{ | ||
int arr[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | ||
f1(arr); | ||
} |
This file contains hidden or 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,11 @@ | ||
CORE | ||
main.c | ||
--replace-all-calls-with-contracts | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
Verification: | ||
This test case checks the handling of a forall expression | ||
nested within a negation. |
This file contains hidden or 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,27 @@ | ||
// clang-format off | ||
int f1(int *arr) __CPROVER_requires( | ||
(__CPROVER_forall { | ||
int i; | ||
(0 <= i && i < 10) ==> arr[i] == 0 | ||
} ? __CPROVER_exists { | ||
int i; | ||
(0 <= i && i < 10) ==> arr[i] == 0 | ||
} : 1 == 0) && | ||
(__CPROVER_forall { | ||
int i; | ||
(0 <= i && i < 10) ==> arr[i] == i | ||
} ? 1 == 0 : | ||
__CPROVER_forall { | ||
int i; | ||
(0 <= i && i < 10) ==> arr[i] == 0 | ||
})) __CPROVER_ensures(__CPROVER_return_value == 0) | ||
// clang-format on | ||
{ | ||
return 0; | ||
} | ||
|
||
int main() | ||
{ | ||
int arr[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | ||
f1(arr); | ||
} |
This file contains hidden or 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,11 @@ | ||
CORE | ||
main.c | ||
--replace-all-calls-with-contracts | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
Verification: | ||
This test case checks the handling of forall and exists expressions | ||
nested within ternary ITE expressions (condition ? true : false). |
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use
const exprt& expression
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, I do not think that it is possible. But I the medium/long term, we should get rid of this parameter entirely.