diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2012-03-26 21:52:43 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2012-03-26 21:52:43 +0000 |
commit | 0e6c50c168a757201bdac4f0d442d248bd85de9c (patch) | |
tree | cab7c4fac50c4ff65785a1a7d606617dad169fb4 /lib | |
parent | 911b3b2e1a9aa8d75d5fdb0465907082684d323a (diff) | |
download | klee-0e6c50c168a757201bdac4f0d442d248bd85de9c.tar.gz |
STPBuilder: fix bv{Zero,One,MinusOne} for the case where width>64
git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@153474 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Solver/STPBuilder.cpp | 20 | ||||
-rw-r--r-- | lib/Solver/STPBuilder.h | 2 |
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/Solver/STPBuilder.cpp b/lib/Solver/STPBuilder.cpp index 28b5c1a5..b5dddad1 100644 --- a/lib/Solver/STPBuilder.cpp +++ b/lib/Solver/STPBuilder.cpp @@ -107,13 +107,13 @@ ExprHandle STPBuilder::getFalse() { return vc_falseExpr(vc); } ExprHandle STPBuilder::bvOne(unsigned width) { - return bvConst32(width, 1); + return bvZExtConst(width, 1); } ExprHandle STPBuilder::bvZero(unsigned width) { - return bvConst32(width, 0); + return bvZExtConst(width, 0); } ExprHandle STPBuilder::bvMinusOne(unsigned width) { - return bvConst64(width, (int64_t) -1); + return bvSExtConst(width, (int64_t) -1); } ExprHandle STPBuilder::bvConst32(unsigned width, uint32_t value) { return vc_bvConstExprFromInt(vc, width, value); @@ -121,6 +121,20 @@ ExprHandle STPBuilder::bvConst32(unsigned width, uint32_t value) { ExprHandle STPBuilder::bvConst64(unsigned width, uint64_t value) { return vc_bvConstExprFromLL(vc, width, value); } +ExprHandle STPBuilder::bvZExtConst(unsigned width, uint64_t value) { + if (width <= 64) + return bvConst64(width, value); + + ExprHandle expr = bvConst64(64, value), zero = bvConst64(64, 0); + for (width -= 64; width > 64; width -= 64) + expr = vc_bvConcatExpr(vc, zero, expr); + return vc_bvConcatExpr(vc, bvConst64(width, 0), expr); +} +ExprHandle STPBuilder::bvSExtConst(unsigned width, uint64_t value) { + if (width <= 64) + return bvConst64(width, value); + return vc_bvSignExtend(vc, bvConst64(64, value), width); +} ExprHandle STPBuilder::bvBoolExtract(ExprHandle expr, int bit) { return vc_eqExpr(vc, bvExtract(expr, bit, bit), bvOne(1)); diff --git a/lib/Solver/STPBuilder.h b/lib/Solver/STPBuilder.h index a4d6d0f8..7cc026bc 100644 --- a/lib/Solver/STPBuilder.h +++ b/lib/Solver/STPBuilder.h @@ -81,6 +81,8 @@ private: ExprHandle bvMinusOne(unsigned width); ExprHandle bvConst32(unsigned width, uint32_t value); ExprHandle bvConst64(unsigned width, uint64_t value); + ExprHandle bvZExtConst(unsigned width, uint64_t value); + ExprHandle bvSExtConst(unsigned width, uint64_t value); ExprHandle bvBoolExtract(ExprHandle expr, int bit); ExprHandle bvExtract(ExprHandle expr, unsigned top, unsigned bottom); |