From 179a8930253e7e81dda77fda1db11a6d11b22f14 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 29 Jul 2011 17:49:56 +0000 Subject: 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 --- lib/Core/Context.cpp | 6 +++++- lib/Core/Executor.cpp | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/Core') 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::createCoerceToPointerType(ref e) { +ref Expr::createSExtToPointerWidth(ref e) { + return SExtExpr::create(e, Context::get().getPointerWidth()); +} + +ref Expr::createZExtToPointerWidth(ref 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 size = Expr::createPointer(elementSize); if (ai->isArrayAllocation()) { ref 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 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(operand)) { ref index = - evalConstant(c)->ZExt(Context::get().getPointerWidth()); + evalConstant(c)->SExt(Context::get().getPointerWidth()); ref addend = index->Mul(ConstantExpr::alloc(elementSize, Context::get().getPointerWidth())); -- cgit 1.4.1