2019-03-26 01:47:45 +08:00
|
|
|
//== Z3Solver.cpp -----------------------------------------------*- C++ -*--==//
|
2017-04-05 03:52:25 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-04-05 03:52:25 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-03-26 01:47:45 +08:00
|
|
|
#include "llvm/ADT/Twine.h"
|
|
|
|
#include "llvm/Config/config.h"
|
|
|
|
#include "llvm/Support/SMTAPI.h"
|
|
|
|
#include <set>
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2019-03-26 01:47:45 +08:00
|
|
|
using namespace llvm;
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2019-03-26 01:47:45 +08:00
|
|
|
#if LLVM_WITH_Z3
|
2017-04-05 03:52:25 +08:00
|
|
|
|
|
|
|
#include <z3.h>
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2018-07-26 03:34:48 +08:00
|
|
|
/// Configuration class for Z3
|
2017-04-05 03:52:25 +08:00
|
|
|
class Z3Config {
|
|
|
|
friend class Z3Context;
|
|
|
|
|
|
|
|
Z3_config Config;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Z3Config() : Config(Z3_mk_config()) {
|
|
|
|
// Enable model finding
|
|
|
|
Z3_set_param_value(Config, "model", "true");
|
|
|
|
// Disable proof generation
|
|
|
|
Z3_set_param_value(Config, "proof", "false");
|
|
|
|
// Set timeout to 15000ms = 15s
|
|
|
|
Z3_set_param_value(Config, "timeout", "15000");
|
|
|
|
}
|
|
|
|
|
|
|
|
~Z3Config() { Z3_del_config(Config); }
|
|
|
|
}; // end class Z3Config
|
|
|
|
|
2018-07-26 03:34:48 +08:00
|
|
|
// Function used to report errors
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
void Z3ErrorHandler(Z3_context Context, Z3_error_code Error) {
|
|
|
|
llvm::report_fatal_error("Z3 error: " +
|
2018-11-12 14:48:02 +08:00
|
|
|
llvm::Twine(Z3_get_error_msg(Context, Error)));
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
}
|
|
|
|
|
2018-07-26 03:34:48 +08:00
|
|
|
/// Wrapper for Z3 context
|
2018-08-23 21:20:18 +08:00
|
|
|
class Z3Context {
|
2017-04-05 03:52:25 +08:00
|
|
|
public:
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
Z3_context Context;
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-08-23 21:20:18 +08:00
|
|
|
Z3Context() {
|
[analyzer] Create generic SMT Context class
Summary:
This patch creates `SMTContext` which will wrap a specific SMT context, through `SMTSolverContext`.
The templated `SMTSolverContext` class it's a simple wrapper around a SMT specific context (currently only used in the Z3 backend), while `Z3Context` inherits `SMTSolverContext<Z3_context>` and implements solver specific operations like initialization and destruction of the context.
This separation was done because:
1. We might want to keep one single context, shared across different `SMTConstraintManager`s. It can be achieved by constructing a `SMTContext`, through a function like `CreateSMTContext(Z3)`, `CreateSMTContext(BOOLECTOR)`, etc. The rest of the CSA only need to know about `SMTContext`, so maybe it's a good idea moving `SMTSolverContext` to a separate header in the future.
2. Any generic SMT operation will only require one `SMTSolverContext`object, which can access the specific context by calling `getContext()`.
Reviewers: NoQ, george.karpenkov
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49233
llvm-svn: 337914
2018-07-25 20:49:07 +08:00
|
|
|
Context = Z3_mk_context_rc(Z3Config().Config);
|
2018-07-26 03:34:48 +08:00
|
|
|
// The error function is set here because the context is the first object
|
|
|
|
// created by the backend
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
Z3_set_error_handler(Context, Z3ErrorHandler);
|
[analyzer] Create generic SMT Context class
Summary:
This patch creates `SMTContext` which will wrap a specific SMT context, through `SMTSolverContext`.
The templated `SMTSolverContext` class it's a simple wrapper around a SMT specific context (currently only used in the Z3 backend), while `Z3Context` inherits `SMTSolverContext<Z3_context>` and implements solver specific operations like initialization and destruction of the context.
This separation was done because:
1. We might want to keep one single context, shared across different `SMTConstraintManager`s. It can be achieved by constructing a `SMTContext`, through a function like `CreateSMTContext(Z3)`, `CreateSMTContext(BOOLECTOR)`, etc. The rest of the CSA only need to know about `SMTContext`, so maybe it's a good idea moving `SMTSolverContext` to a separate header in the future.
2. Any generic SMT operation will only require one `SMTSolverContext`object, which can access the specific context by calling `getContext()`.
Reviewers: NoQ, george.karpenkov
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49233
llvm-svn: 337914
2018-07-25 20:49:07 +08:00
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
virtual ~Z3Context() {
|
|
|
|
Z3_del_context(Context);
|
[analyzer] Create generic SMT Context class
Summary:
This patch creates `SMTContext` which will wrap a specific SMT context, through `SMTSolverContext`.
The templated `SMTSolverContext` class it's a simple wrapper around a SMT specific context (currently only used in the Z3 backend), while `Z3Context` inherits `SMTSolverContext<Z3_context>` and implements solver specific operations like initialization and destruction of the context.
This separation was done because:
1. We might want to keep one single context, shared across different `SMTConstraintManager`s. It can be achieved by constructing a `SMTContext`, through a function like `CreateSMTContext(Z3)`, `CreateSMTContext(BOOLECTOR)`, etc. The rest of the CSA only need to know about `SMTContext`, so maybe it's a good idea moving `SMTSolverContext` to a separate header in the future.
2. Any generic SMT operation will only require one `SMTSolverContext`object, which can access the specific context by calling `getContext()`.
Reviewers: NoQ, george.karpenkov
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49233
llvm-svn: 337914
2018-07-25 20:49:07 +08:00
|
|
|
Context = nullptr;
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
}; // end class Z3Context
|
|
|
|
|
2018-07-26 03:34:48 +08:00
|
|
|
/// Wrapper for Z3 Sort
|
2018-07-25 20:49:15 +08:00
|
|
|
class Z3Sort : public SMTSort {
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
friend class Z3Solver;
|
|
|
|
|
|
|
|
Z3Context &Context;
|
2017-04-05 03:52:25 +08:00
|
|
|
|
|
|
|
Z3_sort Sort;
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
public:
|
2018-07-26 03:34:48 +08:00
|
|
|
/// Default constructor, mainly used by make_shared
|
2018-11-29 01:22:49 +08:00
|
|
|
Z3Sort(Z3Context &C, Z3_sort ZS) : Context(C), Sort(ZS) {
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
Z3_inc_ref(Context.Context, reinterpret_cast<Z3_ast>(Sort));
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Override implicit copy constructor for correct reference counting.
|
2018-11-29 01:22:49 +08:00
|
|
|
Z3Sort(const Z3Sort &Other) : Context(Other.Context), Sort(Other.Sort) {
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
Z3_inc_ref(Context.Context, reinterpret_cast<Z3_ast>(Sort));
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2018-11-29 01:22:49 +08:00
|
|
|
/// Override implicit copy assignment constructor for correct reference
|
|
|
|
/// counting.
|
|
|
|
Z3Sort &operator=(const Z3Sort &Other) {
|
|
|
|
Z3_inc_ref(Context.Context, reinterpret_cast<Z3_ast>(Other.Sort));
|
|
|
|
Z3_dec_ref(Context.Context, reinterpret_cast<Z3_ast>(Sort));
|
|
|
|
Sort = Other.Sort;
|
2017-04-05 03:52:25 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-11-29 01:22:49 +08:00
|
|
|
Z3Sort(Z3Sort &&Other) = delete;
|
|
|
|
Z3Sort &operator=(Z3Sort &&Other) = delete;
|
|
|
|
|
2017-04-05 03:52:25 +08:00
|
|
|
~Z3Sort() {
|
|
|
|
if (Sort)
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
Z3_dec_ref(Context.Context, reinterpret_cast<Z3_ast>(Sort));
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2019-03-15 10:30:07 +08:00
|
|
|
void Profile(llvm::FoldingSetNodeID &ID) const override {
|
2019-02-07 11:17:36 +08:00
|
|
|
ID.AddInteger(
|
|
|
|
Z3_get_ast_id(Context.Context, reinterpret_cast<Z3_ast>(Sort)));
|
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:15 +08:00
|
|
|
bool isBitvectorSortImpl() const override {
|
|
|
|
return (Z3_get_sort_kind(Context.Context, Sort) == Z3_BV_SORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isFloatSortImpl() const override {
|
|
|
|
return (Z3_get_sort_kind(Context.Context, Sort) == Z3_FLOATING_POINT_SORT);
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:15 +08:00
|
|
|
bool isBooleanSortImpl() const override {
|
|
|
|
return (Z3_get_sort_kind(Context.Context, Sort) == Z3_BOOL_SORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getBitvectorSortSizeImpl() const override {
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
return Z3_get_bv_sort_size(Context.Context, Sort);
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:15 +08:00
|
|
|
unsigned getFloatSortSizeImpl() const override {
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
return Z3_fpa_get_ebits(Context.Context, Sort) +
|
|
|
|
Z3_fpa_get_sbits(Context.Context, Sort);
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:15 +08:00
|
|
|
bool equal_to(SMTSort const &Other) const override {
|
|
|
|
return Z3_is_eq_sort(Context.Context, Sort,
|
|
|
|
static_cast<const Z3Sort &>(Other).Sort);
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:15 +08:00
|
|
|
void print(raw_ostream &OS) const override {
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
OS << Z3_sort_to_string(Context.Context, Sort);
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
}; // end class Z3Sort
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
static const Z3Sort &toZ3Sort(const SMTSort &S) {
|
|
|
|
return static_cast<const Z3Sort &>(S);
|
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:19 +08:00
|
|
|
class Z3Expr : public SMTExpr {
|
2017-04-05 03:52:25 +08:00
|
|
|
friend class Z3Solver;
|
|
|
|
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
Z3Context &Context;
|
2017-04-05 03:52:25 +08:00
|
|
|
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
Z3_ast AST;
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
public:
|
2018-07-25 20:49:19 +08:00
|
|
|
Z3Expr(Z3Context &C, Z3_ast ZA) : SMTExpr(), Context(C), AST(ZA) {
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
Z3_inc_ref(Context.Context, AST);
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Override implicit copy constructor for correct reference counting.
|
2018-07-25 20:49:19 +08:00
|
|
|
Z3Expr(const Z3Expr &Copy) : SMTExpr(), Context(Copy.Context), AST(Copy.AST) {
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
Z3_inc_ref(Context.Context, AST);
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-11-29 01:22:49 +08:00
|
|
|
/// Override implicit copy assignment constructor for correct reference
|
|
|
|
/// counting.
|
|
|
|
Z3Expr &operator=(const Z3Expr &Other) {
|
|
|
|
Z3_inc_ref(Context.Context, Other.AST);
|
|
|
|
Z3_dec_ref(Context.Context, AST);
|
|
|
|
AST = Other.AST;
|
2017-04-05 03:52:25 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-11-29 01:22:49 +08:00
|
|
|
Z3Expr(Z3Expr &&Other) = delete;
|
|
|
|
Z3Expr &operator=(Z3Expr &&Other) = delete;
|
|
|
|
|
2017-04-05 03:52:25 +08:00
|
|
|
~Z3Expr() {
|
|
|
|
if (AST)
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
Z3_dec_ref(Context.Context, AST);
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:19 +08:00
|
|
|
void Profile(llvm::FoldingSetNodeID &ID) const override {
|
2019-02-07 11:17:36 +08:00
|
|
|
ID.AddInteger(Z3_get_ast_id(Context.Context, AST));
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Comparison of AST equality, not model equivalence.
|
2018-07-25 20:49:19 +08:00
|
|
|
bool equal_to(SMTExpr const &Other) const override {
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
assert(Z3_is_eq_sort(Context.Context, Z3_get_sort(Context.Context, AST),
|
2018-07-25 20:49:19 +08:00
|
|
|
Z3_get_sort(Context.Context,
|
|
|
|
static_cast<const Z3Expr &>(Other).AST)) &&
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
"AST's must have the same sort");
|
2018-07-25 20:49:19 +08:00
|
|
|
return Z3_is_eq_ast(Context.Context, AST,
|
|
|
|
static_cast<const Z3Expr &>(Other).AST);
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:19 +08:00
|
|
|
void print(raw_ostream &OS) const override {
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
OS << Z3_ast_to_string(Context.Context, AST);
|
|
|
|
}
|
|
|
|
}; // end class Z3Expr
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
static const Z3Expr &toZ3Expr(const SMTExpr &E) {
|
|
|
|
return static_cast<const Z3Expr &>(E);
|
|
|
|
}
|
|
|
|
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
class Z3Model {
|
|
|
|
friend class Z3Solver;
|
|
|
|
|
|
|
|
Z3Context &Context;
|
|
|
|
|
|
|
|
Z3_model Model;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Z3Model(Z3Context &C, Z3_model ZM) : Context(C), Model(ZM) {
|
|
|
|
Z3_model_inc_ref(Context.Context, Model);
|
|
|
|
}
|
|
|
|
|
2018-11-29 01:22:49 +08:00
|
|
|
Z3Model(const Z3Model &Other) = delete;
|
|
|
|
Z3Model(Z3Model &&Other) = delete;
|
|
|
|
Z3Model &operator=(Z3Model &Other) = delete;
|
|
|
|
Z3Model &operator=(Z3Model &&Other) = delete;
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
|
|
|
|
~Z3Model() {
|
|
|
|
if (Model)
|
|
|
|
Z3_model_dec_ref(Context.Context, Model);
|
|
|
|
}
|
|
|
|
|
|
|
|
void print(raw_ostream &OS) const {
|
|
|
|
OS << Z3_model_to_string(Context.Context, Model);
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVM_DUMP_METHOD void dump() const { print(llvm::errs()); }
|
|
|
|
}; // end class Z3Model
|
|
|
|
|
2018-07-25 20:49:19 +08:00
|
|
|
/// Get the corresponding IEEE floating-point type for a given bitwidth.
|
|
|
|
static const llvm::fltSemantics &getFloatSemantics(unsigned BitWidth) {
|
|
|
|
switch (BitWidth) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unsupported floating-point semantics!");
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
return llvm::APFloat::IEEEhalf();
|
|
|
|
case 32:
|
|
|
|
return llvm::APFloat::IEEEsingle();
|
|
|
|
case 64:
|
|
|
|
return llvm::APFloat::IEEEdouble();
|
|
|
|
case 128:
|
|
|
|
return llvm::APFloat::IEEEquad();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine whether two float semantics are equivalent
|
|
|
|
static bool areEquivalent(const llvm::fltSemantics &LHS,
|
|
|
|
const llvm::fltSemantics &RHS) {
|
|
|
|
return (llvm::APFloat::semanticsPrecision(LHS) ==
|
|
|
|
llvm::APFloat::semanticsPrecision(RHS)) &&
|
|
|
|
(llvm::APFloat::semanticsMinExponent(LHS) ==
|
|
|
|
llvm::APFloat::semanticsMinExponent(RHS)) &&
|
|
|
|
(llvm::APFloat::semanticsMaxExponent(LHS) ==
|
|
|
|
llvm::APFloat::semanticsMaxExponent(RHS)) &&
|
|
|
|
(llvm::APFloat::semanticsSizeInBits(LHS) ==
|
|
|
|
llvm::APFloat::semanticsSizeInBits(RHS));
|
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
class Z3Solver : public SMTSolver {
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
friend class Z3ConstraintManager;
|
|
|
|
|
|
|
|
Z3Context Context;
|
|
|
|
|
|
|
|
Z3_solver Solver;
|
|
|
|
|
2019-02-07 11:17:36 +08:00
|
|
|
// Cache Sorts
|
|
|
|
std::set<Z3Sort> CachedSorts;
|
|
|
|
|
|
|
|
// Cache Exprs
|
|
|
|
std::set<Z3Expr> CachedExprs;
|
|
|
|
|
[analyzer] Moved non solver specific code from Z3ConstraintManager to SMTConstraintManager
Summary:
This patch moves a lot of code from `Z3ConstraintManager` to `SMTConstraintManager`, leaving only the necessary:
* `canReasonAbout` which returns if a Solver can handle a given `SVal` (should be moved to `SMTSolver` in the future).
* `removeDeadBindings`, `assumeExpr` and `print`: methods that need to use `ConstraintZ3Ty`, can probably be moved to `SMTConstraintManager` in the future.
The patch creates a new file, `SMTConstraintManager.cpp` with the moved code. Conceptually, this is move in the right direction and needs further improvements: `SMTConstraintManager` still does a lot of things that are not required by a `ConstraintManager`.
We ought to move the unrelated to `SMTSolver` and remove everything that's not related to a `ConstraintManager`. In particular, we could remove `addRangeConstraints` and `isModelFeasible`, and make the refutation manager create an Z3Solver directly.
Reviewers: NoQ, george.karpenkov
Reviewed By: george.karpenkov
Subscribers: mgorny, xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49668
llvm-svn: 337919
2018-07-25 20:49:29 +08:00
|
|
|
public:
|
2018-11-29 01:22:49 +08:00
|
|
|
Z3Solver() : Solver(Z3_mk_simple_solver(Context.Context)) {
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
Z3_solver_inc_ref(Context.Context, Solver);
|
|
|
|
}
|
|
|
|
|
2018-11-29 01:22:49 +08:00
|
|
|
Z3Solver(const Z3Solver &Other) = delete;
|
|
|
|
Z3Solver(Z3Solver &&Other) = delete;
|
|
|
|
Z3Solver &operator=(Z3Solver &Other) = delete;
|
|
|
|
Z3Solver &operator=(Z3Solver &&Other) = delete;
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
|
|
|
|
~Z3Solver() {
|
|
|
|
if (Solver)
|
|
|
|
Z3_solver_dec_ref(Context.Context, Solver);
|
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
void addConstraint(const SMTExprRef &Exp) const override {
|
|
|
|
Z3_solver_assert(Context.Context, Solver, toZ3Expr(*Exp).AST);
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
}
|
|
|
|
|
2019-02-07 11:17:36 +08:00
|
|
|
// Given an SMTSort, adds/retrives it from the cache and returns
|
|
|
|
// an SMTSortRef to the SMTSort in the cache
|
|
|
|
SMTSortRef newSortRef(const SMTSort &Sort) {
|
|
|
|
auto It = CachedSorts.insert(toZ3Sort(Sort));
|
|
|
|
return &(*It.first);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Given an SMTExpr, adds/retrives it from the cache and returns
|
|
|
|
// an SMTExprRef to the SMTExpr in the cache
|
|
|
|
SMTExprRef newExprRef(const SMTExpr &Exp) {
|
|
|
|
auto It = CachedExprs.insert(toZ3Expr(Exp));
|
|
|
|
return &(*It.first);
|
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTSortRef getBoolSort() override {
|
2019-02-07 11:17:36 +08:00
|
|
|
return newSortRef(Z3Sort(Context, Z3_mk_bool_sort(Context.Context)));
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTSortRef getBitvectorSort(unsigned BitWidth) override {
|
2019-02-07 11:17:36 +08:00
|
|
|
return newSortRef(
|
|
|
|
Z3Sort(Context, Z3_mk_bv_sort(Context.Context, BitWidth)));
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTSortRef getSort(const SMTExprRef &Exp) override {
|
2019-02-07 11:17:36 +08:00
|
|
|
return newSortRef(
|
|
|
|
Z3Sort(Context, Z3_get_sort(Context.Context, toZ3Expr(*Exp).AST)));
|
2018-07-25 20:49:23 +08:00
|
|
|
}
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTSortRef getFloat16Sort() override {
|
2019-02-07 11:17:36 +08:00
|
|
|
return newSortRef(Z3Sort(Context, Z3_mk_fpa_sort_16(Context.Context)));
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTSortRef getFloat32Sort() override {
|
2019-02-07 11:17:36 +08:00
|
|
|
return newSortRef(Z3Sort(Context, Z3_mk_fpa_sort_32(Context.Context)));
|
2018-07-25 20:49:23 +08:00
|
|
|
}
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTSortRef getFloat64Sort() override {
|
2019-02-07 11:17:36 +08:00
|
|
|
return newSortRef(Z3Sort(Context, Z3_mk_fpa_sort_64(Context.Context)));
|
2018-07-25 20:49:23 +08:00
|
|
|
}
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTSortRef getFloat128Sort() override {
|
2019-02-07 11:17:36 +08:00
|
|
|
return newSortRef(Z3Sort(Context, Z3_mk_fpa_sort_128(Context.Context)));
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVNeg(const SMTExprRef &Exp) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvneg(Context.Context, toZ3Expr(*Exp).AST)));
|
|
|
|
}
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVNot(const SMTExprRef &Exp) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvnot(Context.Context, toZ3Expr(*Exp).AST)));
|
|
|
|
}
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkNot(const SMTExprRef &Exp) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_not(Context.Context, toZ3Expr(*Exp).AST)));
|
|
|
|
}
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVAdd(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvadd(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVSub(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvsub(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVMul(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvmul(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVSRem(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvsrem(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVURem(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvurem(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVSDiv(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvsdiv(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVUDiv(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvudiv(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVShl(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvshl(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVAshr(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvashr(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVLshr(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvlshr(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVXor(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvxor(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVOr(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvor(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVAnd(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvand(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVUlt(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvult(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVSlt(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvslt(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVUgt(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvugt(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVSgt(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvsgt(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVUle(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvule(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVSle(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvsle(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVUge(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvuge(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkBVSge(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_bvsge(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkAnd(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
Z3_ast Args[2] = {toZ3Expr(*LHS).AST, toZ3Expr(*RHS).AST};
|
|
|
|
return newExprRef(Z3Expr(Context, Z3_mk_and(Context.Context, 2, Args)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkOr(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
Z3_ast Args[2] = {toZ3Expr(*LHS).AST, toZ3Expr(*RHS).AST};
|
|
|
|
return newExprRef(Z3Expr(Context, Z3_mk_or(Context.Context, 2, Args)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkEqual(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_eq(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkFPNeg(const SMTExprRef &Exp) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_fpa_neg(Context.Context, toZ3Expr(*Exp).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkFPIsInfinite(const SMTExprRef &Exp) override {
|
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context, Z3_mk_fpa_is_infinite(Context.Context, toZ3Expr(*Exp).AST)));
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkFPIsNaN(const SMTExprRef &Exp) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_fpa_is_nan(Context.Context, toZ3Expr(*Exp).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkFPIsNormal(const SMTExprRef &Exp) override {
|
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context, Z3_mk_fpa_is_normal(Context.Context, toZ3Expr(*Exp).AST)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTExprRef mkFPIsZero(const SMTExprRef &Exp) override {
|
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context, Z3_mk_fpa_is_zero(Context.Context, toZ3Expr(*Exp).AST)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTExprRef mkFPMul(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
SMTExprRef RoundingMode = getFloatRoundingMode();
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context,
|
|
|
|
Z3_mk_fpa_mul(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST, toZ3Expr(*RoundingMode).AST)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTExprRef mkFPDiv(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
SMTExprRef RoundingMode = getFloatRoundingMode();
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context,
|
|
|
|
Z3_mk_fpa_div(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST, toZ3Expr(*RoundingMode).AST)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTExprRef mkFPRem(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_fpa_rem(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTExprRef mkFPAdd(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
SMTExprRef RoundingMode = getFloatRoundingMode();
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context,
|
|
|
|
Z3_mk_fpa_add(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST, toZ3Expr(*RoundingMode).AST)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTExprRef mkFPSub(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
SMTExprRef RoundingMode = getFloatRoundingMode();
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context,
|
|
|
|
Z3_mk_fpa_sub(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST, toZ3Expr(*RoundingMode).AST)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTExprRef mkFPLt(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_fpa_lt(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTExprRef mkFPGt(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_fpa_gt(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef mkFPLe(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_fpa_leq(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTExprRef mkFPGe(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_fpa_geq(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTExprRef mkFPEqual(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_fpa_eq(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTExprRef mkIte(const SMTExprRef &Cond, const SMTExprRef &T,
|
|
|
|
const SMTExprRef &F) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_ite(Context.Context, toZ3Expr(*Cond).AST,
|
|
|
|
toZ3Expr(*T).AST, toZ3Expr(*F).AST)));
|
|
|
|
}
|
|
|
|
|
2018-07-26 03:34:48 +08:00
|
|
|
SMTExprRef mkBVSignExt(unsigned i, const SMTExprRef &Exp) override {
|
2018-07-25 20:49:23 +08:00
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context, Z3_mk_sign_ext(Context.Context, i, toZ3Expr(*Exp).AST)));
|
|
|
|
}
|
|
|
|
|
2018-07-26 03:34:48 +08:00
|
|
|
SMTExprRef mkBVZeroExt(unsigned i, const SMTExprRef &Exp) override {
|
2018-07-25 20:49:23 +08:00
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context, Z3_mk_zero_ext(Context.Context, i, toZ3Expr(*Exp).AST)));
|
|
|
|
}
|
|
|
|
|
2018-07-26 03:34:48 +08:00
|
|
|
SMTExprRef mkBVExtract(unsigned High, unsigned Low,
|
|
|
|
const SMTExprRef &Exp) override {
|
2018-07-25 20:49:23 +08:00
|
|
|
return newExprRef(Z3Expr(Context, Z3_mk_extract(Context.Context, High, Low,
|
|
|
|
toZ3Expr(*Exp).AST)));
|
|
|
|
}
|
|
|
|
|
2019-03-28 00:54:12 +08:00
|
|
|
/// Creates a predicate that checks for overflow in a bitvector addition
|
|
|
|
/// operation
|
|
|
|
SMTExprRef mkBVAddNoOverflow(const SMTExprRef &LHS, const SMTExprRef &RHS,
|
|
|
|
bool isSigned) override {
|
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context, Z3_mk_bvadd_no_overflow(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST, isSigned)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a predicate that checks for underflow in a signed bitvector
|
|
|
|
/// addition operation
|
|
|
|
SMTExprRef mkBVAddNoUnderflow(const SMTExprRef &LHS,
|
|
|
|
const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context, Z3_mk_bvadd_no_underflow(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a predicate that checks for overflow in a signed bitvector
|
|
|
|
/// subtraction operation
|
|
|
|
SMTExprRef mkBVSubNoOverflow(const SMTExprRef &LHS,
|
|
|
|
const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context, Z3_mk_bvsub_no_overflow(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a predicate that checks for underflow in a bitvector subtraction
|
|
|
|
/// operation
|
|
|
|
SMTExprRef mkBVSubNoUnderflow(const SMTExprRef &LHS, const SMTExprRef &RHS,
|
|
|
|
bool isSigned) override {
|
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context, Z3_mk_bvsub_no_underflow(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST, isSigned)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a predicate that checks for overflow in a signed bitvector
|
|
|
|
/// division/modulus operation
|
|
|
|
SMTExprRef mkBVSDivNoOverflow(const SMTExprRef &LHS,
|
|
|
|
const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context, Z3_mk_bvsdiv_no_overflow(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a predicate that checks for overflow in a bitvector negation
|
|
|
|
/// operation
|
|
|
|
SMTExprRef mkBVNegNoOverflow(const SMTExprRef &Exp) override {
|
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context, Z3_mk_bvneg_no_overflow(Context.Context, toZ3Expr(*Exp).AST)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a predicate that checks for overflow in a bitvector multiplication
|
|
|
|
/// operation
|
|
|
|
SMTExprRef mkBVMulNoOverflow(const SMTExprRef &LHS, const SMTExprRef &RHS,
|
|
|
|
bool isSigned) override {
|
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context, Z3_mk_bvmul_no_overflow(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST, isSigned)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a predicate that checks for underflow in a signed bitvector
|
|
|
|
/// multiplication operation
|
|
|
|
SMTExprRef mkBVMulNoUnderflow(const SMTExprRef &LHS,
|
|
|
|
const SMTExprRef &RHS) override {
|
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context, Z3_mk_bvmul_no_underflow(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
|
|
|
|
2018-07-26 03:34:48 +08:00
|
|
|
SMTExprRef mkBVConcat(const SMTExprRef &LHS, const SMTExprRef &RHS) override {
|
2018-07-25 20:49:23 +08:00
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_concat(Context.Context, toZ3Expr(*LHS).AST,
|
|
|
|
toZ3Expr(*RHS).AST)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTExprRef mkFPtoFP(const SMTExprRef &From, const SMTSortRef &To) override {
|
|
|
|
SMTExprRef RoundingMode = getFloatRoundingMode();
|
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context,
|
|
|
|
Z3_mk_fpa_to_fp_float(Context.Context, toZ3Expr(*RoundingMode).AST,
|
|
|
|
toZ3Expr(*From).AST, toZ3Sort(*To).Sort)));
|
|
|
|
}
|
|
|
|
|
[analyzer] Improvements to the SMT API
Summary:
Several improvements in preparation for the new backends.
Refactoring:
- Removed duplicated methods `fromBoolean`, `fromAPSInt`, `fromInt` and `fromAPFloat`. The methods `mkBoolean`, `mkBitvector` and `mkFloat` are now used instead.
- The names of the functions that convert BVs to FPs were swapped (`mkSBVtoFP`, `mkUBVtoFP`, `mkFPtoSBV`, `mkFPtoUBV`).
- Added a couple of comments in function calls.
Crosscheck encoding:
- Changed how constraints are encoded in the refutation manager so it doesn't start with (false OR ...). This change introduces one duplicated line (see file `BugReporterVisitors.cpp`, the `SMTConv::getRangeExpr is called twice, so I can remove this change if the duplication is a problem.
Reviewers: george.karpenkov, NoQ
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin, Szelethus
Differential Revision: https://reviews.llvm.org/D52365
llvm-svn: 343581
2018-10-02 20:55:48 +08:00
|
|
|
SMTExprRef mkSBVtoFP(const SMTExprRef &From, const SMTSortRef &To) override {
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef RoundingMode = getFloatRoundingMode();
|
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context,
|
|
|
|
Z3_mk_fpa_to_fp_signed(Context.Context, toZ3Expr(*RoundingMode).AST,
|
|
|
|
toZ3Expr(*From).AST, toZ3Sort(*To).Sort)));
|
|
|
|
}
|
|
|
|
|
[analyzer] Improvements to the SMT API
Summary:
Several improvements in preparation for the new backends.
Refactoring:
- Removed duplicated methods `fromBoolean`, `fromAPSInt`, `fromInt` and `fromAPFloat`. The methods `mkBoolean`, `mkBitvector` and `mkFloat` are now used instead.
- The names of the functions that convert BVs to FPs were swapped (`mkSBVtoFP`, `mkUBVtoFP`, `mkFPtoSBV`, `mkFPtoUBV`).
- Added a couple of comments in function calls.
Crosscheck encoding:
- Changed how constraints are encoded in the refutation manager so it doesn't start with (false OR ...). This change introduces one duplicated line (see file `BugReporterVisitors.cpp`, the `SMTConv::getRangeExpr is called twice, so I can remove this change if the duplication is a problem.
Reviewers: george.karpenkov, NoQ
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin, Szelethus
Differential Revision: https://reviews.llvm.org/D52365
llvm-svn: 343581
2018-10-02 20:55:48 +08:00
|
|
|
SMTExprRef mkUBVtoFP(const SMTExprRef &From, const SMTSortRef &To) override {
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef RoundingMode = getFloatRoundingMode();
|
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context,
|
|
|
|
Z3_mk_fpa_to_fp_unsigned(Context.Context, toZ3Expr(*RoundingMode).AST,
|
|
|
|
toZ3Expr(*From).AST, toZ3Sort(*To).Sort)));
|
|
|
|
}
|
|
|
|
|
[analyzer] Improvements to the SMT API
Summary:
Several improvements in preparation for the new backends.
Refactoring:
- Removed duplicated methods `fromBoolean`, `fromAPSInt`, `fromInt` and `fromAPFloat`. The methods `mkBoolean`, `mkBitvector` and `mkFloat` are now used instead.
- The names of the functions that convert BVs to FPs were swapped (`mkSBVtoFP`, `mkUBVtoFP`, `mkFPtoSBV`, `mkFPtoUBV`).
- Added a couple of comments in function calls.
Crosscheck encoding:
- Changed how constraints are encoded in the refutation manager so it doesn't start with (false OR ...). This change introduces one duplicated line (see file `BugReporterVisitors.cpp`, the `SMTConv::getRangeExpr is called twice, so I can remove this change if the duplication is a problem.
Reviewers: george.karpenkov, NoQ
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin, Szelethus
Differential Revision: https://reviews.llvm.org/D52365
llvm-svn: 343581
2018-10-02 20:55:48 +08:00
|
|
|
SMTExprRef mkFPtoSBV(const SMTExprRef &From, unsigned ToWidth) override {
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef RoundingMode = getFloatRoundingMode();
|
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context, Z3_mk_fpa_to_sbv(Context.Context, toZ3Expr(*RoundingMode).AST,
|
|
|
|
toZ3Expr(*From).AST, ToWidth)));
|
|
|
|
}
|
|
|
|
|
[analyzer] Improvements to the SMT API
Summary:
Several improvements in preparation for the new backends.
Refactoring:
- Removed duplicated methods `fromBoolean`, `fromAPSInt`, `fromInt` and `fromAPFloat`. The methods `mkBoolean`, `mkBitvector` and `mkFloat` are now used instead.
- The names of the functions that convert BVs to FPs were swapped (`mkSBVtoFP`, `mkUBVtoFP`, `mkFPtoSBV`, `mkFPtoUBV`).
- Added a couple of comments in function calls.
Crosscheck encoding:
- Changed how constraints are encoded in the refutation manager so it doesn't start with (false OR ...). This change introduces one duplicated line (see file `BugReporterVisitors.cpp`, the `SMTConv::getRangeExpr is called twice, so I can remove this change if the duplication is a problem.
Reviewers: george.karpenkov, NoQ
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin, Szelethus
Differential Revision: https://reviews.llvm.org/D52365
llvm-svn: 343581
2018-10-02 20:55:48 +08:00
|
|
|
SMTExprRef mkFPtoUBV(const SMTExprRef &From, unsigned ToWidth) override {
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef RoundingMode = getFloatRoundingMode();
|
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context, Z3_mk_fpa_to_ubv(Context.Context, toZ3Expr(*RoundingMode).AST,
|
|
|
|
toZ3Expr(*From).AST, ToWidth)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTExprRef mkBoolean(const bool b) override {
|
|
|
|
return newExprRef(Z3Expr(Context, b ? Z3_mk_true(Context.Context)
|
|
|
|
: Z3_mk_false(Context.Context)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTExprRef mkBitvector(const llvm::APSInt Int, unsigned BitWidth) override {
|
|
|
|
const SMTSortRef Sort = getBitvectorSort(BitWidth);
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_numeral(Context.Context, Int.toString(10).c_str(),
|
|
|
|
toZ3Sort(*Sort).Sort)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTExprRef mkFloat(const llvm::APFloat Float) override {
|
|
|
|
SMTSortRef Sort =
|
|
|
|
getFloatSort(llvm::APFloat::semanticsSizeInBits(Float.getSemantics()));
|
|
|
|
|
|
|
|
llvm::APSInt Int = llvm::APSInt(Float.bitcastToAPInt(), false);
|
|
|
|
SMTExprRef Z3Int = mkBitvector(Int, Int.getBitWidth());
|
|
|
|
return newExprRef(Z3Expr(
|
|
|
|
Context, Z3_mk_fpa_to_fp_bv(Context.Context, toZ3Expr(*Z3Int).AST,
|
|
|
|
toZ3Sort(*Sort).Sort)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTExprRef mkSymbol(const char *Name, SMTSortRef Sort) override {
|
|
|
|
return newExprRef(
|
|
|
|
Z3Expr(Context, Z3_mk_const(Context.Context,
|
|
|
|
Z3_mk_string_symbol(Context.Context, Name),
|
|
|
|
toZ3Sort(*Sort).Sort)));
|
|
|
|
}
|
|
|
|
|
2018-07-26 19:17:13 +08:00
|
|
|
llvm::APSInt getBitvector(const SMTExprRef &Exp, unsigned BitWidth,
|
|
|
|
bool isUnsigned) override {
|
2018-10-26 01:27:36 +08:00
|
|
|
return llvm::APSInt(
|
|
|
|
llvm::APInt(BitWidth,
|
|
|
|
Z3_get_numeral_string(Context.Context, toZ3Expr(*Exp).AST),
|
|
|
|
10),
|
|
|
|
isUnsigned);
|
2018-07-25 20:49:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool getBoolean(const SMTExprRef &Exp) override {
|
|
|
|
return Z3_get_bool_value(Context.Context, toZ3Expr(*Exp).AST) == Z3_L_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTExprRef getFloatRoundingMode() override {
|
|
|
|
// TODO: Don't assume nearest ties to even rounding mode
|
|
|
|
return newExprRef(Z3Expr(Context, Z3_mk_fpa_rne(Context.Context)));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool toAPFloat(const SMTSortRef &Sort, const SMTExprRef &AST,
|
|
|
|
llvm::APFloat &Float, bool useSemantics) {
|
|
|
|
assert(Sort->isFloatSort() && "Unsupported sort to floating-point!");
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
llvm::APSInt Int(Sort->getFloatSortSize(), true);
|
2017-04-05 03:52:25 +08:00
|
|
|
const llvm::fltSemantics &Semantics =
|
2018-07-25 20:49:23 +08:00
|
|
|
getFloatSemantics(Sort->getFloatSortSize());
|
|
|
|
SMTSortRef BVSort = getBitvectorSort(Sort->getFloatSortSize());
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
if (!toAPSInt(BVSort, AST, Int, true)) {
|
2017-04-05 03:52:25 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:19 +08:00
|
|
|
if (useSemantics && !areEquivalent(Float.getSemantics(), Semantics)) {
|
2017-04-05 03:52:25 +08:00
|
|
|
assert(false && "Floating-point types don't match!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Float = llvm::APFloat(Semantics, Int);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
bool toAPSInt(const SMTSortRef &Sort, const SMTExprRef &AST,
|
|
|
|
llvm::APSInt &Int, bool useSemantics) {
|
|
|
|
if (Sort->isBitvectorSort()) {
|
|
|
|
if (useSemantics && Int.getBitWidth() != Sort->getBitvectorSortSize()) {
|
2017-04-05 03:52:25 +08:00
|
|
|
assert(false && "Bitvector types don't match!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-26 19:17:13 +08:00
|
|
|
// FIXME: This function is also used to retrieve floating-point values,
|
|
|
|
// which can be 16, 32, 64 or 128 bits long. Bitvectors can be anything
|
|
|
|
// between 1 and 64 bits long, which is the reason we have this weird
|
|
|
|
// guard. In the future, we need proper calls in the backend to retrieve
|
|
|
|
// floating-points and its special values (NaN, +/-infinity, +/-zero),
|
|
|
|
// then we can drop this weird condition.
|
|
|
|
if (Sort->getBitvectorSortSize() <= 64 ||
|
|
|
|
Sort->getBitvectorSortSize() == 128) {
|
|
|
|
Int = getBitvector(AST, Int.getBitWidth(), Int.isUnsigned());
|
|
|
|
return true;
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
2018-07-26 19:17:13 +08:00
|
|
|
|
|
|
|
assert(false && "Bitwidth not supported!");
|
|
|
|
return false;
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
2018-07-25 20:49:15 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
if (Sort->isBooleanSort()) {
|
2017-04-05 03:52:25 +08:00
|
|
|
if (useSemantics && Int.getBitWidth() < 1) {
|
|
|
|
assert(false && "Boolean type doesn't match!");
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-25 20:49:15 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
Int = llvm::APSInt(llvm::APInt(Int.getBitWidth(), getBoolean(AST)),
|
|
|
|
Int.isUnsigned());
|
2017-04-05 03:52:25 +08:00
|
|
|
return true;
|
|
|
|
}
|
2018-07-25 20:49:15 +08:00
|
|
|
|
|
|
|
llvm_unreachable("Unsupported sort to integer!");
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
bool getInterpretation(const SMTExprRef &Exp, llvm::APSInt &Int) override {
|
2018-11-29 01:22:49 +08:00
|
|
|
Z3Model Model(Context, Z3_solver_get_model(Context.Context, Solver));
|
2018-07-25 20:49:23 +08:00
|
|
|
Z3_func_decl Func = Z3_get_app_decl(
|
|
|
|
Context.Context, Z3_to_app(Context.Context, toZ3Expr(*Exp).AST));
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
if (Z3_model_has_interp(Context.Context, Model.Model, Func) != Z3_L_TRUE)
|
2017-04-05 03:52:25 +08:00
|
|
|
return false;
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef Assign = newExprRef(
|
|
|
|
Z3Expr(Context,
|
|
|
|
Z3_model_get_const_interp(Context.Context, Model.Model, Func)));
|
|
|
|
SMTSortRef Sort = getSort(Assign);
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
return toAPSInt(Sort, Assign, Int, true);
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
bool getInterpretation(const SMTExprRef &Exp, llvm::APFloat &Float) override {
|
2018-11-29 01:22:49 +08:00
|
|
|
Z3Model Model(Context, Z3_solver_get_model(Context.Context, Solver));
|
2018-07-25 20:49:23 +08:00
|
|
|
Z3_func_decl Func = Z3_get_app_decl(
|
|
|
|
Context.Context, Z3_to_app(Context.Context, toZ3Expr(*Exp).AST));
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
if (Z3_model_has_interp(Context.Context, Model.Model, Func) != Z3_L_TRUE)
|
2017-04-05 03:52:25 +08:00
|
|
|
return false;
|
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
SMTExprRef Assign = newExprRef(
|
|
|
|
Z3Expr(Context,
|
|
|
|
Z3_model_get_const_interp(Context.Context, Model.Model, Func)));
|
|
|
|
SMTSortRef Sort = getSort(Assign);
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
return toAPFloat(Sort, Assign, Float, true);
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2018-08-23 21:21:31 +08:00
|
|
|
Optional<bool> check() const override {
|
2018-07-25 20:49:23 +08:00
|
|
|
Z3_lbool res = Z3_solver_check(Context.Context, Solver);
|
|
|
|
if (res == Z3_L_TRUE)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (res == Z3_L_FALSE)
|
|
|
|
return false;
|
|
|
|
|
2018-08-23 21:21:31 +08:00
|
|
|
return Optional<bool>();
|
2018-07-25 20:49:23 +08:00
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
void push() override { return Z3_solver_push(Context.Context, Solver); }
|
2017-04-05 03:52:25 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
void pop(unsigned NumStates = 1) override {
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
assert(Z3_solver_get_num_scopes(Context.Context, Solver) >= NumStates);
|
|
|
|
return Z3_solver_pop(Context.Context, Solver, NumStates);
|
2017-04-05 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2018-10-26 01:27:42 +08:00
|
|
|
bool isFPSupported() override { return true; }
|
|
|
|
|
2017-04-05 03:52:25 +08:00
|
|
|
/// Reset the solver and remove all constraints.
|
2018-10-14 03:42:10 +08:00
|
|
|
void reset() override { Z3_solver_reset(Context.Context, Solver); }
|
2018-06-04 22:25:58 +08:00
|
|
|
|
2018-07-25 20:49:23 +08:00
|
|
|
void print(raw_ostream &OS) const override {
|
[analyzer] Moved static Context to class member
Summary:
Although it is a big patch, the changes are simple:
1. There is one `Z3_Context` now, member of the `SMTConstraintManager` class.
2. `Z3Expr`, `Z3Sort`, `Z3Model` and `Z3Solver` are constructed with a reference to the `Z3_Context` in `SMTConstraintManager`.
3. All static functions are now members of `Z3Solver`, e.g, the `SMTConstraintManager` now calls `Solver.fromBoolean(false)` instead of `Z3Expr::fromBoolean(false)`.
Most of the patch only move stuff around except:
1. New method `Z3Sort MkSort(const QualType &Ty, unsigned BitWidth)`, that creates a sort based on the `QualType` and its width. Used to simplify the `fromData` method.
Unfortunate consequence of this patch:
1. `getInterpretation` was moved from `Z3Model` class to `Z3Solver`, because it needs to create a `Z3Sort` before returning the interpretation. This can be fixed by changing both `toAPFloat` and `toAPSInt` by removing the dependency of `Z3Sort` (it's only used to check which Sort was created and to retrieve the type width).
Reviewers: NoQ, george.karpenkov, ddcc
Reviewed By: george.karpenkov
Subscribers: xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49236
llvm-svn: 337915
2018-07-25 20:49:11 +08:00
|
|
|
OS << Z3_solver_to_string(Context.Context, Solver);
|
2018-06-04 22:25:58 +08:00
|
|
|
}
|
2017-04-05 03:52:25 +08:00
|
|
|
}; // end class Z3Solver
|
|
|
|
|
[analyzer] Moved non solver specific code from Z3ConstraintManager to SMTConstraintManager
Summary:
This patch moves a lot of code from `Z3ConstraintManager` to `SMTConstraintManager`, leaving only the necessary:
* `canReasonAbout` which returns if a Solver can handle a given `SVal` (should be moved to `SMTSolver` in the future).
* `removeDeadBindings`, `assumeExpr` and `print`: methods that need to use `ConstraintZ3Ty`, can probably be moved to `SMTConstraintManager` in the future.
The patch creates a new file, `SMTConstraintManager.cpp` with the moved code. Conceptually, this is move in the right direction and needs further improvements: `SMTConstraintManager` still does a lot of things that are not required by a `ConstraintManager`.
We ought to move the unrelated to `SMTSolver` and remove everything that's not related to a `ConstraintManager`. In particular, we could remove `addRangeConstraints` and `isModelFeasible`, and make the refutation manager create an Z3Solver directly.
Reviewers: NoQ, george.karpenkov
Reviewed By: george.karpenkov
Subscribers: mgorny, xazax.hun, szepet, a.sidorin
Differential Revision: https://reviews.llvm.org/D49668
llvm-svn: 337919
2018-07-25 20:49:29 +08:00
|
|
|
} // end anonymous namespace
|
2017-04-05 03:52:25 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2019-03-26 01:47:45 +08:00
|
|
|
llvm::SMTSolverRef llvm::CreateZ3Solver() {
|
|
|
|
#if LLVM_WITH_Z3
|
2018-07-25 20:49:43 +08:00
|
|
|
return llvm::make_unique<Z3Solver>();
|
|
|
|
#else
|
2019-03-26 01:47:45 +08:00
|
|
|
llvm::report_fatal_error("LLVM was not compiled with Z3 support, rebuild "
|
|
|
|
"with -DLLVM_ENABLE_Z3_SOLVER=ON",
|
2018-07-25 20:49:43 +08:00
|
|
|
false);
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
2019-03-26 22:25:12 +08:00
|
|
|
|
|
|
|
LLVM_DUMP_METHOD void SMTSort::dump() const { print(llvm::errs()); }
|
|
|
|
LLVM_DUMP_METHOD void SMTExpr::dump() const { print(llvm::errs()); }
|
|
|
|
LLVM_DUMP_METHOD void SMTSolver::dump() const { print(llvm::errs()); }
|