-
Notifications
You must be signed in to change notification settings - Fork 291
Do not use as const with Z3 due to soundness issue
#9011
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
Open
tautschnig
wants to merge
3
commits into
diffblue:develop
Choose a base branch
from
tautschnig:z3-workaround
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+146
−22
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,37 @@ | ||
| // Pins the SMT2 we emit under --z3 when set_to() defines a symbol whose | ||
| // body would otherwise be a `(define-fun ... (lambda ...))`. | ||
| // | ||
| // Z3 rejects `(get-value ...)` on symbols whose `define-fun` body | ||
| // contains a lambda, so smt2_convt::set_to switches to | ||
| // `(declare-fun X () T) (assert (= X body))` whenever | ||
| // use_lambda_for_array is set (currently only Z3). This test | ||
| // exercises the path -- the variable-length unsigned-char array | ||
| // `src` ends up encoded with an `array_comprehension` that produces a | ||
| // lambda body, and the new gate keeps the assignment to the | ||
| // memcpy-source symbol parseable by Z3's get-value while still | ||
| // emitting the lambda in an `assert (= ...)`. | ||
| // | ||
| // A future change that re-enables `use_as_const = true` for Z3 (i.e. | ||
| // once Z3Prover/z3#9550 is fixed and we bump the minimum Z3 version) | ||
| // must also update or remove this regex; the test exists precisely to | ||
| // flag such a silent regression. | ||
|
|
||
| #include <stdint.h> | ||
| #include <string.h> | ||
|
|
||
| int main() | ||
| { | ||
| unsigned char size; | ||
| __CPROVER_assume(size > 1); | ||
| __CPROVER_assume(size < 5); | ||
| __CPROVER_assume(size % 4 == 0); | ||
| unsigned char src[size]; | ||
| src[0] = 0x2a; | ||
| src[1] = 0x2a; | ||
| src[2] = 0x2a; | ||
| src[3] = 0x2a; | ||
| int32_t dest; | ||
| memcpy(&dest, src, size); | ||
| __CPROVER_assert(dest == 0x2a2a2a2a, "memcpy round-trip"); | ||
| return 0; | ||
| } |
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,30 @@ | ||
| CORE broken-cprover-smt-backend no-new-smt | ||
| main.c | ||
| --z3 --outfile - | ||
| activate-multi-line-match | ||
| \(declare-fun \|[^|]*memcpy[^|]*::1::1::src_n!0@1#2\| \(\) \(Array \(_ BitVec (?:32|64)\) \(_ BitVec 8\)\)\)\n\(assert \(= \|[^|]*memcpy[^|]*::1::1::src_n!0@1#2\| \(lambda | ||
| ^EXIT=0$ | ||
| ^SIGNAL=0$ | ||
| -- | ||
| ^warning: ignoring | ||
| -- | ||
| Pins the SMT2 emitted under `--z3` to a `(declare-fun ...) (assert (= ... | ||
| (lambda ...)))` form rather than `(define-fun ... (lambda ...))` -- which Z3 | ||
| rejects on `(get-value ...)`. The lambda comes from CBMC's array | ||
| comprehension lowering for the variable-length `src` array; without the | ||
| `set_to` re-routing introduced when `use_lambda_for_array` is true (gated on | ||
| `use_lambda_for_array`, currently only Z3) the SMT2 would emit a | ||
| `define-fun` body that prevents Z3 from returning a model. | ||
|
|
||
| The regex tolerates the two ways the memcpy SSA symbol is named: | ||
| `memcpy::1::1::src_n` on glibc/BSD targets and | ||
| `__builtin___memcpy_chk::1::1::src_n` on macOS where `<string.h>` | ||
| expands `memcpy(...)` to the FORTIFY_SOURCE-fortified builtin. It | ||
| also accepts either `(_ BitVec 32)` or `(_ BitVec 64)` for the array | ||
| index sort so the test can run on both i386 and 64-bit | ||
| configurations. | ||
|
|
||
| A future change that re-enables `use_as_const = true` for Z3 (i.e. after | ||
| Z3Prover/z3#9550 is fixed and the minimum Z3 version is bumped) must | ||
| also update or remove this regex; the test exists precisely to flag such a | ||
| silent regression. |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.