|
6 | 6 | //
|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
| 9 | +#include "llvm/ADT/SmallString.h" |
9 | 10 | #include "llvm/ADT/Twine.h"
|
10 | 11 | #include "llvm/Config/config.h"
|
11 | 12 | #include "llvm/Support/SMTAPI.h"
|
@@ -723,10 +724,25 @@ class Z3Solver : public SMTSolver {
|
723 | 724 | }
|
724 | 725 |
|
725 | 726 | SMTExprRef mkBitvector(const llvm::APSInt Int, unsigned BitWidth) override {
|
726 |
| - const SMTSortRef Sort = getBitvectorSort(BitWidth); |
727 |
| - return newExprRef( |
728 |
| - Z3Expr(Context, Z3_mk_numeral(Context.Context, Int.toString(10).c_str(), |
729 |
| - toZ3Sort(*Sort).Sort))); |
| 727 | + const Z3_sort Z3Sort = toZ3Sort(*getBitvectorSort(BitWidth)).Sort; |
| 728 | + |
| 729 | + // Slow path, when 64 bits are not enough. |
| 730 | + if (LLVM_UNLIKELY(Int.getBitWidth() > 64u)) { |
| 731 | + SmallString<40> Buffer; |
| 732 | + Int.toString(Buffer, 10); |
| 733 | + return newExprRef(Z3Expr( |
| 734 | + Context, Z3_mk_numeral(Context.Context, Buffer.c_str(), Z3Sort))); |
| 735 | + } |
| 736 | + |
| 737 | + const int64_t BitReprAsSigned = Int.getExtValue(); |
| 738 | + const uint64_t BitReprAsUnsigned = |
| 739 | + reinterpret_cast<const uint64_t &>(BitReprAsSigned); |
| 740 | + |
| 741 | + Z3_ast Literal = |
| 742 | + Int.isSigned() |
| 743 | + ? Z3_mk_int64(Context.Context, BitReprAsSigned, Z3Sort) |
| 744 | + : Z3_mk_unsigned_int64(Context.Context, BitReprAsUnsigned, Z3Sort); |
| 745 | + return newExprRef(Z3Expr(Context, Literal)); |
730 | 746 | }
|
731 | 747 |
|
732 | 748 | SMTExprRef mkFloat(const llvm::APFloat Float) override {
|
|
0 commit comments