-
Notifications
You must be signed in to change notification settings - Fork 294
cprover: add external SMT2 solver backend (--smt2-solver) #9068
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
1
commit into
diffblue:develop
Choose a base branch
from
tautschnig:strata/cprover-smt2-solver-backend
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.
Open
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,7 @@ | ||
| int main() | ||
| { | ||
| int x; | ||
| __CPROVER_assume(x >= 2); | ||
| __CPROVER_assert(x >= 2, "holds"); // passes | ||
| __CPROVER_assert(x >= 3, "may fail"); // fails | ||
| } |
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,14 @@ | ||
| CORE | ||
| main.c | ||
| --external-smt2-solver z3 --solve --inline --no-safety | ||
| ^EXIT=10$ | ||
| ^SIGNAL=0$ | ||
| ^\[main\.assertion\.1\] line \d+ holds: SUCCESS$ | ||
| ^\[main\.assertion\.2\] line \d+ may fail: REFUTED$ | ||
| -- | ||
| ^warning: ignoring | ||
| -- | ||
| Exercises the external SMT2 solver backend (--external-smt2-solver) end to end: | ||
| the state-encoding queries are discharged by an external z3 process instead of | ||
| the built-in SAT backend, and the per-property results are as expected. z3 is | ||
| installed on every CI platform that runs this (CORE) suite. |
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
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
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,46 @@ | ||
| /*******************************************************************\ | ||
|
|
||
| Module: SMT2 decision procedure for cprover state encoding | ||
|
|
||
| Author: Michael Tautschnig | ||
|
|
||
| \*******************************************************************/ | ||
|
|
||
| #ifndef CPROVER_CPROVER_CPROVER_SMT2_DEC_H | ||
| #define CPROVER_CPROVER_CPROVER_SMT2_DEC_H | ||
|
|
||
| #include <solvers/smt2/smt2_dec.h> | ||
|
|
||
| #include <string> | ||
|
|
||
| /// SMT2 decision procedure configured for cprover's state encoding. | ||
| /// Uses datatypes for structs (instead of bitvector flattening) to | ||
| /// support mathematical types (integer, real, string). | ||
| /// | ||
| /// The emitted SMT2 uses solvert::GENERIC, i.e. standard SMT-LIBv2 without | ||
| /// solver-specific options or encodings, so that any SMT2 binary configured | ||
| /// via --external-smt2-solver (z3, cvc5, ...) can discharge the queries. This | ||
| /// trades solver-specific tuning for portability. | ||
| class cprover_smt2_dect : public smt2_dect | ||
| { | ||
| public: | ||
| cprover_smt2_dect( | ||
| const namespacet &_ns, | ||
| const std::string &_solver_binary, | ||
| message_handlert &_message_handler) | ||
|
tautschnig marked this conversation as resolved.
|
||
| : smt2_dect( | ||
| _ns, | ||
| "", | ||
| "cprover", | ||
| "ALL", | ||
| smt2_convt::solvert::GENERIC, | ||
| _solver_binary, | ||
| _message_handler) | ||
| { | ||
| use_array_of_bool = true; | ||
| use_as_const = true; | ||
| use_datatypes = true; | ||
| } | ||
| }; | ||
|
|
||
| #endif // CPROVER_CPROVER_CPROVER_SMT2_DEC_H | ||
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
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,79 @@ | ||
| /*******************************************************************\ | ||
|
|
||
| Module: State-encoding solver backend selection | ||
|
|
||
| Author: Daniel Kroening, dkr@amazon.com | ||
|
|
||
| \*******************************************************************/ | ||
|
|
||
| /// \file | ||
| /// Construction of the decision procedure used for cprover's state-encoding | ||
| /// queries: either the built-in SAT backend (bit-vector flattening) or an | ||
| /// external SMT2 solver. | ||
|
|
||
| #ifndef CPROVER_CPROVER_STATE_ENCODING_SOLVER_FACTORY_H | ||
| #define CPROVER_CPROVER_STATE_ENCODING_SOLVER_FACTORY_H | ||
|
|
||
| #include <util/invariant.h> | ||
| #include <util/message.h> | ||
| #include <util/namespace.h> | ||
|
|
||
| #include <solvers/decision_procedure.h> | ||
| #include <solvers/sat/satcheck.h> | ||
|
|
||
| #include "bv_pointers_wide.h" | ||
| #include "cprover_smt2_dec.h" | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| /// Owns the solver objects backing a state-encoding query and hands out the | ||
| /// \ref decision_proceduret to use. Exactly one backend is populated: the | ||
| /// external SMT2 decision procedure when a solver binary is configured, or the | ||
| /// SAT backend (satcheck + bit-vector flattening) otherwise. | ||
| struct state_encoding_solvert | ||
| { | ||
| // SAT backend (used when no SMT2 solver binary is configured) | ||
| std::unique_ptr<satcheckt> satcheck; | ||
| std::unique_ptr<bv_pointers_widet> bv; | ||
| // external SMT2 backend | ||
| std::unique_ptr<cprover_smt2_dect> smt2; | ||
|
|
||
| /// The decision procedure to drive the query with. | ||
| decision_proceduret &solver() | ||
| { | ||
| if(smt2 != nullptr) | ||
| return *smt2; | ||
| INVARIANT( | ||
| bv != nullptr, "state-encoding solver bundle must have a backend"); | ||
| return *bv; | ||
| } | ||
| }; | ||
|
|
||
| /// Construct the state-encoding solver backend. When \p smt2_solver_binary is | ||
| /// non-empty the external SMT2 solver is used; otherwise the built-in SAT | ||
| /// backend is used. Centralises the selection so the call sites stay | ||
| /// consistent. | ||
| inline state_encoding_solvert make_state_encoding_solver( | ||
| const namespacet &ns, | ||
| const std::string &smt2_solver_binary, | ||
| message_handlert &message_handler) | ||
| { | ||
| state_encoding_solvert result; | ||
|
|
||
| if(smt2_solver_binary.empty()) | ||
| { | ||
| result.satcheck = std::make_unique<satcheckt>(message_handler); | ||
| result.bv = std::make_unique<bv_pointers_widet>( | ||
| ns, *result.satcheck, message_handler); | ||
| } | ||
| else | ||
| { | ||
| result.smt2 = std::make_unique<cprover_smt2_dect>( | ||
| ns, smt2_solver_binary, message_handler); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| #endif // CPROVER_CPROVER_STATE_ENCODING_SOLVER_FACTORY_H |
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.