about summary refs log tree commit diff homepage
path: root/lib/Core
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2011-07-29 17:49:56 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2011-07-29 17:49:56 +0000
commit179a8930253e7e81dda77fda1db11a6d11b22f14 (patch)
treee8f1ceb0ef844deb88adc2c8fea1890993a73c2b /lib/Core
parentf1b9d5d45886d7c989f14a57fcc0851b8b219917 (diff)
downloadklee-179a8930253e7e81dda77fda1db11a6d11b22f14.tar.gz
Sign extend, rather than zero extend, narrow gep indices
For example, clang creates these for ++ and -- operations on pointers
on 64-bit platforms.

git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@136474 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Core')
-rw-r--r--lib/Core/Context.cpp6
-rw-r--r--lib/Core/Executor.cpp6
2 files changed, 8 insertions, 4 deletions
diff --git a/lib/Core/Context.cpp b/lib/Core/Context.cpp
index 45dbdca0..979970aa 100644
--- a/lib/Core/Context.cpp
+++ b/lib/Core/Context.cpp
@@ -35,7 +35,11 @@ const Context &Context::get() {
 // FIXME: This is a total hack, just to avoid a layering issue until this stuff
 // moves out of Expr.
 
-ref<Expr> Expr::createCoerceToPointerType(ref<Expr> e) {
+ref<Expr> Expr::createSExtToPointerWidth(ref<Expr> e) {
+  return SExtExpr::create(e, Context::get().getPointerWidth());
+}
+
+ref<Expr> Expr::createZExtToPointerWidth(ref<Expr> e) {
   return ZExtExpr::create(e, Context::get().getPointerWidth());
 }
 
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 48a8b57a..1a37498f 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -1863,7 +1863,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
     ref<Expr> size = Expr::createPointer(elementSize);
     if (ai->isArrayAllocation()) {
       ref<Expr> count = eval(ki, 0, state).value;
-      count = Expr::createCoerceToPointerType(count);
+      count = Expr::createZExtToPointerWidth(count);
       size = MulExpr::create(size, count);
     }
     bool isLocal = i->getOpcode()==Instruction::Alloca;
@@ -1899,7 +1899,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
       uint64_t elementSize = it->second;
       ref<Expr> index = eval(ki, it->first, state).value;
       base = AddExpr::create(base,
-                             MulExpr::create(Expr::createCoerceToPointerType(index),
+                             MulExpr::create(Expr::createSExtToPointerWidth(index),
                                              Expr::createPointer(elementSize)));
     }
     if (kgepi->offset)
@@ -2320,7 +2320,7 @@ void Executor::computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie) {
       Value *operand = ii.getOperand();
       if (Constant *c = dyn_cast<Constant>(operand)) {
         ref<ConstantExpr> index = 
-          evalConstant(c)->ZExt(Context::get().getPointerWidth());
+          evalConstant(c)->SExt(Context::get().getPointerWidth());
         ref<ConstantExpr> addend = 
           index->Mul(ConstantExpr::alloc(elementSize,
                                          Context::get().getPointerWidth()));