-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7786 from remi-delmas-3000/contracts-fix-quantifi…
…er-vars CONTRACTS: fix fresh symbols for quantified vars
- Loading branch information
Showing
4 changed files
with
63 additions
and
12 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
regression/contracts-dfcc/quantifiers-loops-fresh-bound-vars-smt/main.c
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,32 @@ | ||
#include <stdlib.h> | ||
void foo(char *dst, const char *src, size_t n) | ||
// clang-format off | ||
__CPROVER_requires(__CPROVER_is_fresh(src, n)) | ||
__CPROVER_requires(__CPROVER_is_fresh(dst, n)) | ||
__CPROVER_assigns(__CPROVER_object_from(dst)) | ||
__CPROVER_ensures(__CPROVER_forall { | ||
size_t j; | ||
j < n ==> dst[j] == src[j] | ||
}) | ||
// clang-format on | ||
{ | ||
for(size_t i = 0; i < n; i++) | ||
// clang-format off | ||
__CPROVER_assigns(i, __CPROVER_object_from(dst)) | ||
__CPROVER_loop_invariant(i <= n) | ||
__CPROVER_loop_invariant( | ||
__CPROVER_forall { size_t j; j < i ==> dst[j] == src[j] }) | ||
// clang-format on | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
char *dst; | ||
char *src; | ||
size_t n; | ||
foo(dst, src, n); | ||
return 0; | ||
} |
15 changes: 15 additions & 0 deletions
15
regression/contracts-dfcc/quantifiers-loops-fresh-bound-vars-smt/test.desc
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,15 @@ | ||
CORE dfcc-only smt-backend broken-cprover-smt-backend | ||
main.c | ||
--dfcc main --apply-loop-contracts --enforce-contract foo --malloc-may-fail --malloc-fail-null _ --z3 --slice-formula | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
Tests support for quantifiers in loop contracts with the SMT backend. | ||
When quantified loop invariants are used, they are inserted three times | ||
in the transformed program (base case assertion, step case assumption, | ||
step case assertion), and each occurrence needs to be rewritten with fresh | ||
symbols for the quantified variables. The SMT solver would with an error | ||
whenever this renaming is not properly done. |
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
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