diff options
author | Martin Nowack <martin@se.inf.tu-dresden.de> | 2017-07-22 01:03:44 +0200 |
---|---|---|
committer | Martin Nowack <martin@se.inf.tu-dresden.de> | 2017-07-23 12:18:35 +0200 |
commit | 37e92d0c802524c19a9a84164253639aac47fee3 (patch) | |
tree | 6b9036dcc8415544eb5a6d5cace7fddb2bfc323a /lib/Core/Executor.cpp | |
parent | 9fb2f5666d5f8c7c2f335fc8408883a0cf958964 (diff) | |
download | klee-37e92d0c802524c19a9a84164253639aac47fee3.tar.gz |
Remove support for LLVM < 3.4
Request LLVM 3.4 as minimal requirement for KLEE
Diffstat (limited to 'lib/Core/Executor.cpp')
-rw-r--r-- | lib/Core/Executor.cpp | 159 |
1 files changed, 9 insertions, 150 deletions
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp index ff842fd1..5560a3e5 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp @@ -49,7 +49,6 @@ #include "klee/Internal/System/MemoryUsage.h" #include "klee/SolverStats.h" -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) #include "llvm/IR/Function.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" @@ -61,22 +60,6 @@ #include "llvm/IR/Module.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/TypeBuilder.h" -#else -#include "llvm/Attributes.h" -#include "llvm/BasicBlock.h" -#include "llvm/Constants.h" -#include "llvm/Function.h" -#include "llvm/Instructions.h" -#include "llvm/IntrinsicInst.h" -#include "llvm/LLVMContext.h" -#include "llvm/Module.h" -#if LLVM_VERSION_CODE <= LLVM_VERSION(3, 1) -#include "llvm/Target/TargetData.h" -#else -#include "llvm/DataLayout.h" -#include "llvm/TypeBuilder.h" -#endif -#endif #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/CommandLine.h" @@ -293,17 +276,10 @@ namespace { KLEE_LLVM_CL_VAL_END), cl::ZeroOrMore); -#if LLVM_VERSION_CODE < LLVM_VERSION(3, 0) - cl::opt<unsigned int> - StopAfterNInstructions("stop-after-n-instructions", - cl::desc("Stop execution after specified number of instructions (default=0 (off))"), - cl::init(0)); -#else cl::opt<unsigned long long> StopAfterNInstructions("stop-after-n-instructions", cl::desc("Stop execution after specified number of instructions (default=0 (off))"), cl::init(0)); -#endif cl::opt<unsigned> MaxForks("max-forks", @@ -420,11 +396,7 @@ const Module *Executor::setModule(llvm::Module *module, kmodule = new KModule(module); // Initialize the context. -#if LLVM_VERSION_CODE <= LLVM_VERSION(3, 1) - TargetData *TD = kmodule->targetData; -#else DataLayout *TD = kmodule->targetData; -#endif Context::initialize(TD->isLittleEndian(), (Expr::Width) TD->getPointerSizeInBits()); @@ -469,11 +441,7 @@ Executor::~Executor() { void Executor::initializeGlobalObject(ExecutionState &state, ObjectState *os, const Constant *c, unsigned offset) { -#if LLVM_VERSION_CODE <= LLVM_VERSION(3, 1) - TargetData *targetData = kmodule->targetData; -#else DataLayout *targetData = kmodule->targetData; -#endif if (const ConstantVector *cp = dyn_cast<ConstantVector>(c)) { unsigned elementSize = targetData->getTypeStoreSize(cp->getType()->getElementType()); @@ -496,7 +464,6 @@ void Executor::initializeGlobalObject(ExecutionState &state, ObjectState *os, for (unsigned i=0, e=cs->getNumOperands(); i != e; ++i) initializeGlobalObject(state, os, cs->getOperand(i), offset + sl->getElementOffset(i)); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 1) } else if (const ConstantDataSequential *cds = dyn_cast<ConstantDataSequential>(c)) { unsigned elementSize = @@ -504,7 +471,6 @@ void Executor::initializeGlobalObject(ExecutionState &state, ObjectState *os, for (unsigned i=0, e=cds->getNumElements(); i != e; ++i) initializeGlobalObject(state, os, cds->getElementAsConstant(i), offset + i*elementSize); -#endif } else if (!isa<UndefValue>(c)) { unsigned StoreBits = targetData->getTypeStoreSizeInBits(c->getType()); ref<ConstantExpr> C = evalConstant(c); @@ -539,10 +505,6 @@ void Executor::initializeGlobals(ExecutionState &state) { if (m->getModuleInlineAsm() != "") klee_warning("executable has module level assembly (ignoring)"); -#if LLVM_VERSION_CODE < LLVM_VERSION(3, 3) - assert(m->lib_begin() == m->lib_end() && - "XXX do not support dependent libraries"); -#endif // represent function globals using the address of the actual llvm function // object. given that we use malloc to allocate memory in states this also // ensures that we won't conflict. we don't need to allocate a memory object @@ -610,7 +572,7 @@ void Executor::initializeGlobals(ExecutionState &state) { // better we could support user definition, or use the EXE style // hack where we check the object file information. - LLVM_TYPE_Q Type *ty = i->getType()->getElementType(); + Type *ty = i->getType()->getElementType(); uint64_t size = 0; if (ty->isSized()) { size = kmodule->targetData->getTypeStoreSize(ty); @@ -659,7 +621,7 @@ void Executor::initializeGlobals(ExecutionState &state) { os->write8(offset, ((unsigned char*)addr)[offset]); } } else { - LLVM_TYPE_Q Type *ty = i->getType()->getElementType(); + Type *ty = i->getType()->getElementType(); uint64_t size = kmodule->targetData->getTypeStoreSize(ty); MemoryObject *mo = memory->allocate(size, /*isLocal=*/false, /*isGlobal=*/true, /*allocSite=*/v, @@ -1063,7 +1025,6 @@ ref<klee::ConstantExpr> Executor::evalConstant(const Constant *c) { return Expr::createPointer(0); } else if (isa<UndefValue>(c) || isa<ConstantAggregateZero>(c)) { return ConstantExpr::create(0, getWidthForLLVMType(c->getType())); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 1) } else if (const ConstantDataSequential *cds = dyn_cast<ConstantDataSequential>(c)) { std::vector<ref<Expr> > kids; @@ -1073,7 +1034,6 @@ ref<klee::ConstantExpr> Executor::evalConstant(const Constant *c) { } ref<Expr> res = ConcatExpr::createN(kids.size(), kids.data()); return cast<ConstantExpr>(res); -#endif } else if (const ConstantStruct *cs = dyn_cast<ConstantStruct>(c)) { const StructLayout *sl = kmodule->targetData->getStructLayout(cs->getType()); llvm::SmallVector<ref<Expr>, 4> kids; @@ -1581,7 +1541,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { } if (!isVoidReturn) { - LLVM_TYPE_Q Type *t = caller->getType(); + Type *t = caller->getType(); if (t != Type::getVoidTy(i->getContext())) { // may need to do coercion due to bitcasts Expr::Width from = result->getWidth(); @@ -1592,13 +1552,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { CallSite(cast<CallInst>(caller))); // XXX need to check other param attrs ? -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) bool isSExt = cs.paramHasAttr(0, llvm::Attribute::SExt); -#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 2) - bool isSExt = cs.paramHasAttr(0, llvm::Attributes::SExt); -#else - bool isSExt = cs.paramHasAttr(0, llvm::Attribute::SExt); -#endif if (isSExt) { result = SExtExpr::create(result, to); } else { @@ -1619,29 +1573,6 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { } break; } -#if LLVM_VERSION_CODE < LLVM_VERSION(3, 1) - case Instruction::Unwind: { - for (;;) { - KInstruction *kcaller = state.stack.back().caller; - state.popFrame(); - - if (statsTracker) - statsTracker->framePopped(state); - - if (state.stack.empty()) { - terminateStateOnExecError(state, "unwind from initial stack frame"); - break; - } else { - Instruction *caller = kcaller->inst; - if (InvokeInst *ii = dyn_cast<InvokeInst>(caller)) { - transferToBasicBlock(ii->getUnwindDest(), caller->getParent(), state); - break; - } - } - } - break; - } -#endif case Instruction::Br: { BranchInst *bi = cast<BranchInst>(i); if (bi->isUnconditional()) { @@ -1676,14 +1607,9 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { if (ConstantExpr *CE = dyn_cast<ConstantExpr>(cond)) { // Somewhat gross to create these all the time, but fine till we // switch to an internal rep. - LLVM_TYPE_Q llvm::IntegerType *Ty = - cast<IntegerType>(si->getCondition()->getType()); + llvm::IntegerType *Ty = cast<IntegerType>(si->getCondition()->getType()); ConstantInt *ci = ConstantInt::get(Ty, CE->getZExtValue()); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 1) unsigned index = si->findCaseValue(ci).getSuccessorIndex(); -#else - unsigned index = si->findCaseValue(ci); -#endif transferToBasicBlock(si->getSuccessor(index), si->getParent(), state); } else { // Handle possible different branch targets @@ -1699,20 +1625,11 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { std::map<ref<Expr>, BasicBlock *> expressionOrder; // Iterate through all non-default cases and order them by expressions -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 1) for (SwitchInst::CaseIt i = si->case_begin(), e = si->case_end(); i != e; ++i) { ref<Expr> value = evalConstant(i.getCaseValue()); -#else - for (unsigned i = 1, cases = si->getNumCases(); i < cases; ++i) { - ref<Expr> value = evalConstant(si->getCaseValue(i)); -#endif -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 1) BasicBlock *caseSuccessor = i.getCaseSuccessor(); -#else - BasicBlock *caseSuccessor = si->getSuccessor(i); -#endif expressionOrder.insert(std::make_pair(value, caseSuccessor)); } @@ -1848,13 +1765,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { if (from != to) { // XXX need to check other param attrs ? -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) bool isSExt = cs.paramHasAttr(i+1, llvm::Attribute::SExt); -#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 2) - bool isSExt = cs.paramHasAttr(i+1, llvm::Attributes::SExt); -#else - bool isSExt = cs.paramHasAttr(i+1, llvm::Attribute::SExt); -#endif if (isSExt) { arguments[i] = SExtExpr::create(arguments[i], to); } else { @@ -1910,11 +1821,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { break; } case Instruction::PHI: { -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 0) ref<Expr> result = eval(ki, state.incomingBBIndex, state).value; -#else - ref<Expr> result = eval(ki, state.incomingBBIndex * 2, state).value; -#endif bindLocal(ki, state, result); break; } @@ -2233,13 +2140,8 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { !fpWidthToSemantics(right->getWidth())) return terminateStateOnExecError(state, "Unsupported FAdd operation"); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) llvm::APFloat Res(*fpWidthToSemantics(left->getWidth()), left->getAPValue()); Res.add(APFloat(*fpWidthToSemantics(right->getWidth()),right->getAPValue()), APFloat::rmNearestTiesToEven); -#else - llvm::APFloat Res(left->getAPValue()); - Res.add(APFloat(right->getAPValue()), APFloat::rmNearestTiesToEven); -#endif bindLocal(ki, state, ConstantExpr::alloc(Res.bitcastToAPInt())); break; } @@ -2252,13 +2154,8 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { if (!fpWidthToSemantics(left->getWidth()) || !fpWidthToSemantics(right->getWidth())) return terminateStateOnExecError(state, "Unsupported FSub operation"); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) llvm::APFloat Res(*fpWidthToSemantics(left->getWidth()), left->getAPValue()); Res.subtract(APFloat(*fpWidthToSemantics(right->getWidth()), right->getAPValue()), APFloat::rmNearestTiesToEven); -#else - llvm::APFloat Res(left->getAPValue()); - Res.subtract(APFloat(right->getAPValue()), APFloat::rmNearestTiesToEven); -#endif bindLocal(ki, state, ConstantExpr::alloc(Res.bitcastToAPInt())); break; } @@ -2272,13 +2169,8 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { !fpWidthToSemantics(right->getWidth())) return terminateStateOnExecError(state, "Unsupported FMul operation"); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) llvm::APFloat Res(*fpWidthToSemantics(left->getWidth()), left->getAPValue()); Res.multiply(APFloat(*fpWidthToSemantics(right->getWidth()), right->getAPValue()), APFloat::rmNearestTiesToEven); -#else - llvm::APFloat Res(left->getAPValue()); - Res.multiply(APFloat(right->getAPValue()), APFloat::rmNearestTiesToEven); -#endif bindLocal(ki, state, ConstantExpr::alloc(Res.bitcastToAPInt())); break; } @@ -2292,13 +2184,8 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { !fpWidthToSemantics(right->getWidth())) return terminateStateOnExecError(state, "Unsupported FDiv operation"); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) llvm::APFloat Res(*fpWidthToSemantics(left->getWidth()), left->getAPValue()); Res.divide(APFloat(*fpWidthToSemantics(right->getWidth()), right->getAPValue()), APFloat::rmNearestTiesToEven); -#else - llvm::APFloat Res(left->getAPValue()); - Res.divide(APFloat(right->getAPValue()), APFloat::rmNearestTiesToEven); -#endif bindLocal(ki, state, ConstantExpr::alloc(Res.bitcastToAPInt())); break; } @@ -2311,14 +2198,9 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { if (!fpWidthToSemantics(left->getWidth()) || !fpWidthToSemantics(right->getWidth())) return terminateStateOnExecError(state, "Unsupported FRem operation"); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) llvm::APFloat Res(*fpWidthToSemantics(left->getWidth()), left->getAPValue()); Res.mod(APFloat(*fpWidthToSemantics(right->getWidth()),right->getAPValue()), APFloat::rmNearestTiesToEven); -#else - llvm::APFloat Res(left->getAPValue()); - Res.mod(APFloat(right->getAPValue()), APFloat::rmNearestTiesToEven); -#endif bindLocal(ki, state, ConstantExpr::alloc(Res.bitcastToAPInt())); break; } @@ -2331,11 +2213,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { if (!fpWidthToSemantics(arg->getWidth()) || resultType > arg->getWidth()) return terminateStateOnExecError(state, "Unsupported FPTrunc operation"); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) llvm::APFloat Res(*fpWidthToSemantics(arg->getWidth()), arg->getAPValue()); -#else - llvm::APFloat Res(arg->getAPValue()); -#endif bool losesInfo = false; Res.convert(*fpWidthToSemantics(resultType), llvm::APFloat::rmNearestTiesToEven, @@ -2351,11 +2229,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { "floating point"); if (!fpWidthToSemantics(arg->getWidth()) || arg->getWidth() > resultType) return terminateStateOnExecError(state, "Unsupported FPExt operation"); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) llvm::APFloat Res(*fpWidthToSemantics(arg->getWidth()), arg->getAPValue()); -#else - llvm::APFloat Res(arg->getAPValue()); -#endif bool losesInfo = false; Res.convert(*fpWidthToSemantics(resultType), llvm::APFloat::rmNearestTiesToEven, @@ -2372,11 +2246,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { if (!fpWidthToSemantics(arg->getWidth()) || resultType > 64) return terminateStateOnExecError(state, "Unsupported FPToUI operation"); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) llvm::APFloat Arg(*fpWidthToSemantics(arg->getWidth()), arg->getAPValue()); -#else - llvm::APFloat Arg(arg->getAPValue()); -#endif uint64_t value = 0; bool isExact = true; Arg.convertToInteger(&value, resultType, false, @@ -2392,12 +2262,8 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { "floating point"); if (!fpWidthToSemantics(arg->getWidth()) || resultType > 64) return terminateStateOnExecError(state, "Unsupported FPToSI operation"); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) llvm::APFloat Arg(*fpWidthToSemantics(arg->getWidth()), arg->getAPValue()); -#else - llvm::APFloat Arg(arg->getAPValue()); -#endif uint64_t value = 0; bool isExact = true; Arg.convertToInteger(&value, resultType, true, @@ -2448,13 +2314,8 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { !fpWidthToSemantics(right->getWidth())) return terminateStateOnExecError(state, "Unsupported FCmp operation"); -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) APFloat LHS(*fpWidthToSemantics(left->getWidth()),left->getAPValue()); APFloat RHS(*fpWidthToSemantics(right->getWidth()),right->getAPValue()); -#else - APFloat LHS(left->getAPValue()); - APFloat RHS(right->getAPValue()); -#endif APFloat::cmpResult CmpRes = LHS.compare(RHS); bool Result = false; @@ -2572,12 +2433,10 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { bindLocal(ki, state, result); break; } -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) case Instruction::Fence: { // Ignore for now break; } -#endif case Instruction::InsertElement: { InsertElementInst *iei = cast<InsertElementInst>(i); ref<Expr> vec = eval(ki, 0, state).value; @@ -2697,7 +2556,7 @@ void Executor::computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie) { ConstantExpr::alloc(0, Context::get().getPointerWidth()); uint64_t index = 1; for (TypeIt ii = ib; ii != ie; ++ii) { - if (LLVM_TYPE_Q StructType *st = dyn_cast<StructType>(*ii)) { + if (StructType *st = dyn_cast<StructType>(*ii)) { const StructLayout *sl = kmodule->targetData->getStructLayout(st); const ConstantInt *ci = cast<ConstantInt>(ii.getOperand()); uint64_t addend = sl->getElementOffset((unsigned) ci->getZExtValue()); @@ -3189,7 +3048,7 @@ void Executor::callExternalFunction(ExecutionState &state, return; } - LLVM_TYPE_Q Type *resultType = target->inst->getType(); + Type *resultType = target->inst->getType(); if (resultType != Type::getVoidTy(function->getContext())) { ref<Expr> e = ConstantExpr::fromMemory((void*) args, getWidthForLLVMType(resultType)); @@ -3860,7 +3719,7 @@ void Executor::doImpliedValueConcretization(ExecutionState &state, } } -Expr::Width Executor::getWidthForLLVMType(LLVM_TYPE_Q llvm::Type *type) const { +Expr::Width Executor::getWidthForLLVMType(llvm::Type *type) const { return kmodule->targetData->getTypeSizeInBits(type); } @@ -3869,13 +3728,13 @@ size_t Executor::getAllocationAlignment(const llvm::Value *allocSite) const { // and should fetch the default from elsewhere. const size_t forcedAlignment = 8; size_t alignment = 0; - LLVM_TYPE_Q llvm::Type *type = NULL; + llvm::Type *type = NULL; std::string allocationSiteName(allocSite->getName().str()); if (const GlobalValue *GV = dyn_cast<GlobalValue>(allocSite)) { alignment = GV->getAlignment(); if (const GlobalVariable *globalVar = dyn_cast<GlobalVariable>(GV)) { // All GlobalVariables's have pointer type - LLVM_TYPE_Q llvm::PointerType *ptrType = + llvm::PointerType *ptrType = dyn_cast<llvm::PointerType>(globalVar->getType()); assert(ptrType && "globalVar's type is not a pointer"); type = ptrType->getElementType(); |