OBS-URL: https://build.opensuse.org/package/show/devel:tools:statica/klee?expand=0&rev=4
863 lines
35 KiB
Diff
863 lines
35 KiB
Diff
From: =?UTF-8?q?Richard=20Trembeck=C3=BD?= <richardt@centrum.sk>
|
|
Date: Wed, 4 May 2016 15:21:45 +0200
|
|
Subject: Make KLEE compile against LLVM 3.8
|
|
Patch-mainline: no
|
|
|
|
Mainly explicit casts from pointers to iterators and back.
|
|
|
|
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
|
|
---
|
|
lib/Core/Executor.cpp | 47 ++++++++++++++++++++------
|
|
lib/Core/StatsTracker.cpp | 66 +++++++++++++++++++++++++++---------
|
|
lib/Module/Checks.cpp | 34 +++++++++++--------
|
|
lib/Module/InstructionInfoTable.cpp | 15 +++++++--
|
|
lib/Module/IntrinsicCleaner.cpp | 12 +++++--
|
|
lib/Module/KModule.cpp | 67 +++++++++++++++++++++++++++----------
|
|
lib/Module/LowerSwitch.cpp | 15 ++++++++-
|
|
lib/Module/ModuleUtil.cpp | 65 ++++++++++++++++++++++++-----------
|
|
lib/Module/Optimize.cpp | 13 ++++++-
|
|
lib/Module/RaiseAsm.cpp | 4 +++
|
|
tools/klee/main.cpp | 32 +++++++++++++++---
|
|
11 files changed, 282 insertions(+), 88 deletions(-)
|
|
|
|
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
|
|
index 80b8289d1486..b3ec990dc9ae 100644
|
|
--- a/lib/Core/Executor.cpp
|
|
+++ b/lib/Core/Executor.cpp
|
|
@@ -554,7 +554,11 @@ void Executor::initializeGlobals(ExecutionState &state) {
|
|
// ensures that we won't conflict. we don't need to allocate a memory object
|
|
// since reading/writing via a function pointer is unsupported anyway.
|
|
for (Module::iterator i = m->begin(), ie = m->end(); i != ie; ++i) {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ Function *f = static_cast<Function *>(i);
|
|
+#else
|
|
Function *f = i;
|
|
+#endif
|
|
ref<ConstantExpr> addr(0);
|
|
|
|
// If the symbol has external weak linkage then it is implicitly
|
|
@@ -608,6 +612,11 @@ void Executor::initializeGlobals(ExecutionState &state) {
|
|
for (Module::const_global_iterator i = m->global_begin(),
|
|
e = m->global_end();
|
|
i != e; ++i) {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ const GlobalVariable *v = static_cast<const GlobalVariable *>(i);
|
|
+#else
|
|
+ const GlobalVariable *v = i;
|
|
+#endif
|
|
if (i->isDeclaration()) {
|
|
// FIXME: We have no general way of handling unknown external
|
|
// symbols. If we really cared about making external stuff work
|
|
@@ -638,11 +647,10 @@ void Executor::initializeGlobals(ExecutionState &state) {
|
|
klee_warning("Unable to find size for global variable: %.*s (use will result in out of bounds access)",
|
|
(int)i->getName().size(), i->getName().data());
|
|
}
|
|
-
|
|
- MemoryObject *mo = memory->allocate(size, false, true, i);
|
|
+ MemoryObject *mo = memory->allocate(size, false, true, v);
|
|
ObjectState *os = bindObjectInState(state, mo, false);
|
|
- globalObjects.insert(std::make_pair(i, mo));
|
|
- globalAddresses.insert(std::make_pair(i, mo->getBaseExpr()));
|
|
+ globalObjects.insert(std::make_pair(v, mo));
|
|
+ globalAddresses.insert(std::make_pair(v, mo->getBaseExpr()));
|
|
|
|
// Program already running = object already initialized. Read
|
|
// concrete value and write it to our copy.
|
|
@@ -667,8 +675,8 @@ void Executor::initializeGlobals(ExecutionState &state) {
|
|
if (!mo)
|
|
llvm::report_fatal_error("out of memory");
|
|
ObjectState *os = bindObjectInState(state, mo, false);
|
|
- globalObjects.insert(std::make_pair(i, mo));
|
|
- globalAddresses.insert(std::make_pair(i, mo->getBaseExpr()));
|
|
+ globalObjects.insert(std::make_pair(v, mo));
|
|
+ globalAddresses.insert(std::make_pair(v, mo->getBaseExpr()));
|
|
|
|
if (!i->hasInitializer())
|
|
os->initializeToRandom();
|
|
@@ -679,8 +687,13 @@ void Executor::initializeGlobals(ExecutionState &state) {
|
|
for (Module::alias_iterator i = m->alias_begin(), ie = m->alias_end();
|
|
i != ie; ++i) {
|
|
// Map the alias to its aliasee's address. This works because we have
|
|
- // addresses for everything, even undefined functions.
|
|
+ // addresses for everything, even undefined functions.
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ globalAddresses.insert(std::make_pair(static_cast<GlobalAlias *>(i),
|
|
+ evalConstant(i->getAliasee())));
|
|
+#else
|
|
globalAddresses.insert(std::make_pair(i, evalConstant(i->getAliasee())));
|
|
+#endif
|
|
}
|
|
|
|
// once all objects are allocated, do the actual initialization
|
|
@@ -688,7 +701,12 @@ void Executor::initializeGlobals(ExecutionState &state) {
|
|
e = m->global_end();
|
|
i != e; ++i) {
|
|
if (i->hasInitializer()) {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ MemoryObject *mo =
|
|
+ globalObjects.find(static_cast<const GlobalVariable *>(i))->second;
|
|
+#else
|
|
MemoryObject *mo = globalObjects.find(i)->second;
|
|
+#endif
|
|
const ObjectState *os = state.addressSpace.findObject(mo);
|
|
assert(os);
|
|
ObjectState *wos = state.addressSpace.getWriteable(mo, os);
|
|
@@ -2303,8 +2321,13 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
|
|
return terminateStateOnExecError(state, "Unsupported FRem operation");
|
|
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
|
|
llvm::APFloat Res(*fpWidthToSemantics(left->getWidth()), left->getAPValue());
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ Res.mod(
|
|
+ APFloat(*fpWidthToSemantics(right->getWidth()), right->getAPValue()));
|
|
+#else
|
|
Res.mod(APFloat(*fpWidthToSemantics(right->getWidth()),right->getAPValue()),
|
|
APFloat::rmNearestTiesToEven);
|
|
+#endif
|
|
#else
|
|
llvm::APFloat Res(left->getAPValue());
|
|
Res.mod(APFloat(right->getAPValue()), APFloat::rmNearestTiesToEven);
|
|
@@ -3563,9 +3586,13 @@ void Executor::runFunctionAsMain(Function *f,
|
|
arguments.push_back(ConstantExpr::alloc(argc, Expr::Int32));
|
|
|
|
if (++ai!=ae) {
|
|
- argvMO = memory->allocate((argc+1+envc+1+1) * NumPtrBytes, false, true,
|
|
- f->begin()->begin());
|
|
-
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ Instruction *first = static_cast<Instruction *>(f->begin()->begin());
|
|
+#else
|
|
+ Instruction *first = f->begin()->begin();
|
|
+#endif
|
|
+ argvMO = memory->allocate((argc + 1 + envc + 1 + 1) * NumPtrBytes, false,
|
|
+ true, first);
|
|
if (!argvMO)
|
|
klee_error("Could not allocate memory for function arguments");
|
|
|
|
diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp
|
|
index ae12708c130c..fff266aca19b 100644
|
|
--- a/lib/Core/StatsTracker.cpp
|
|
+++ b/lib/Core/StatsTracker.cpp
|
|
@@ -162,10 +162,14 @@ static bool instructionIsCoverable(Instruction *i) {
|
|
if (i->getOpcode() == Instruction::Unreachable) {
|
|
BasicBlock *bb = i->getParent();
|
|
BasicBlock::iterator it(i);
|
|
- if (it==bb->begin()) {
|
|
+ if (it == bb->begin()) {
|
|
return true;
|
|
} else {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ Instruction *prev = static_cast<Instruction *>(--it);
|
|
+#else
|
|
Instruction *prev = --it;
|
|
+#endif
|
|
if (isa<CallInst>(prev) || isa<InvokeInst>(prev)) {
|
|
CallSite cs(prev);
|
|
Function *target =
|
|
@@ -543,7 +547,12 @@ void StatsTracker::writeIStats() {
|
|
// Always try to write the filename before the function name, as otherwise
|
|
// KCachegrind can create two entries for the function, one with an
|
|
// unnamed file and one without.
|
|
- const InstructionInfo &ii = executor.kmodule->infos->getFunctionInfo(fnIt);
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ Function *fn = static_cast<Function *>(fnIt);
|
|
+#else
|
|
+ Function *fn = fnIt;
|
|
+#endif
|
|
+ const InstructionInfo &ii = executor.kmodule->infos->getFunctionInfo(fn);
|
|
if (ii.file != sourceFile) {
|
|
of << "fl=" << ii.file << "\n";
|
|
sourceFile = ii.file;
|
|
@@ -639,9 +648,17 @@ static std::vector<Instruction*> getSuccs(Instruction *i) {
|
|
|
|
if (i==bb->getTerminator()) {
|
|
for (succ_iterator it = succ_begin(bb), ie = succ_end(bb); it != ie; ++it)
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ res.push_back(static_cast<Instruction *>(it->begin()));
|
|
+#else
|
|
res.push_back(it->begin());
|
|
+#endif
|
|
} else {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ res.push_back(static_cast<Instruction *>(++(i->getIterator())));
|
|
+#else
|
|
res.push_back(++BasicBlock::iterator(i));
|
|
+#endif
|
|
}
|
|
|
|
return res;
|
|
@@ -688,20 +705,24 @@ void StatsTracker::computeReachableUncovered() {
|
|
bbIt != bb_ie; ++bbIt) {
|
|
for (BasicBlock::iterator it = bbIt->begin(), ie = bbIt->end();
|
|
it != ie; ++it) {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ Instruction *inst = static_cast<Instruction *>(it);
|
|
+#else
|
|
+ Instruction *inst = it;
|
|
+#endif
|
|
if (isa<CallInst>(it) || isa<InvokeInst>(it)) {
|
|
- CallSite cs(it);
|
|
+ CallSite cs(inst);
|
|
if (isa<InlineAsm>(cs.getCalledValue())) {
|
|
// We can never call through here so assume no targets
|
|
// (which should be correct anyhow).
|
|
- callTargets.insert(std::make_pair(it,
|
|
+ callTargets.insert(std::make_pair(inst,
|
|
std::vector<Function*>()));
|
|
} else if (Function *target = getDirectCallTarget(
|
|
cs, /*moduleIsFullyLinked=*/true)) {
|
|
- callTargets[it].push_back(target);
|
|
+ callTargets[inst].push_back(target);
|
|
} else {
|
|
- callTargets[it] =
|
|
- std::vector<Function*>(km->escapingFunctions.begin(),
|
|
- km->escapingFunctions.end());
|
|
+ callTargets[inst] = std::vector<Function *>(
|
|
+ km->escapingFunctions.begin(), km->escapingFunctions.end());
|
|
}
|
|
}
|
|
}
|
|
@@ -720,14 +741,19 @@ void StatsTracker::computeReachableUncovered() {
|
|
std::vector<Instruction *> instructions;
|
|
for (Module::iterator fnIt = m->begin(), fn_ie = m->end();
|
|
fnIt != fn_ie; ++fnIt) {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ Function *fn = static_cast<Function *>(fnIt);
|
|
+#else
|
|
+ Function *fn = fnIt;
|
|
+#endif
|
|
if (fnIt->isDeclaration()) {
|
|
if (fnIt->doesNotReturn()) {
|
|
- functionShortestPath[fnIt] = 0;
|
|
+ functionShortestPath[fn] = 0;
|
|
} else {
|
|
- functionShortestPath[fnIt] = 1; // whatever
|
|
+ functionShortestPath[fn] = 1; // whatever
|
|
}
|
|
} else {
|
|
- functionShortestPath[fnIt] = 0;
|
|
+ functionShortestPath[fn] = 0;
|
|
}
|
|
|
|
// Not sure if I should bother to preorder here. XXX I should.
|
|
@@ -735,8 +761,13 @@ void StatsTracker::computeReachableUncovered() {
|
|
bbIt != bb_ie; ++bbIt) {
|
|
for (BasicBlock::iterator it = bbIt->begin(), ie = bbIt->end();
|
|
it != ie; ++it) {
|
|
- instructions.push_back(it);
|
|
- unsigned id = infos.getInfo(it).id;
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ Instruction *inst = static_cast<Instruction *>(it);
|
|
+#else
|
|
+ Instruction *inst = it;
|
|
+#endif
|
|
+ instructions.push_back(inst);
|
|
+ unsigned id = infos.getInfo(inst).id;
|
|
sm.setIndexedValue(stats::minDistToReturn,
|
|
id,
|
|
isa<ReturnInst>(it)
|
|
@@ -817,8 +848,13 @@ void StatsTracker::computeReachableUncovered() {
|
|
bbIt != bb_ie; ++bbIt) {
|
|
for (BasicBlock::iterator it = bbIt->begin(), ie = bbIt->end();
|
|
it != ie; ++it) {
|
|
- unsigned id = infos.getInfo(it).id;
|
|
- instructions.push_back(&*it);
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ Instruction *inst = static_cast<Instruction *>(it);
|
|
+#else
|
|
+ Instruction *inst = it;
|
|
+#endif
|
|
+ unsigned id = infos.getInfo(inst).id;
|
|
+ instructions.push_back(inst);
|
|
sm.setIndexedValue(stats::minDistToUncovered,
|
|
id,
|
|
sm.getIndexedValue(stats::uncoveredInstructions, id));
|
|
diff --git a/lib/Module/Checks.cpp b/lib/Module/Checks.cpp
|
|
index 7d9b72841753..2a1681f3a7c5 100644
|
|
--- a/lib/Module/Checks.cpp
|
|
+++ b/lib/Module/Checks.cpp
|
|
@@ -64,14 +64,17 @@ bool DivCheckPass::runOnModule(Module &M) {
|
|
Instruction::BinaryOps opcode = binOp->getOpcode();
|
|
if (opcode == Instruction::SDiv || opcode == Instruction::UDiv ||
|
|
opcode == Instruction::SRem || opcode == Instruction::URem) {
|
|
-
|
|
- CastInst *denominator =
|
|
- CastInst::CreateIntegerCast(i->getOperand(1),
|
|
- Type::getInt64Ty(getGlobalContext()),
|
|
- false, /* sign doesn't matter */
|
|
- "int_cast_to_i64",
|
|
- i);
|
|
-
|
|
+
|
|
+ CastInst *denominator = CastInst::CreateIntegerCast(
|
|
+ i->getOperand(1), Type::getInt64Ty(getGlobalContext()),
|
|
+ false, /* sign doesn't matter */
|
|
+ "int_cast_to_i64",
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ static_cast<Instruction *>(i));
|
|
+#else
|
|
+ i);
|
|
+#endif
|
|
+
|
|
// Lazily bind the function to avoid always importing it.
|
|
if (!divZeroCheckFunction) {
|
|
Constant *fc = M.getOrInsertFunction("klee_div_zero_check",
|
|
@@ -121,12 +124,15 @@ bool OvershiftCheckPass::runOnModule(Module &M) {
|
|
ConstantInt *bitWidthC = ConstantInt::get(Type::getInt64Ty(getGlobalContext()),bitWidth,false);
|
|
args.push_back(bitWidthC);
|
|
|
|
- CastInst *shift =
|
|
- CastInst::CreateIntegerCast(i->getOperand(1),
|
|
- Type::getInt64Ty(getGlobalContext()),
|
|
- false, /* sign doesn't matter */
|
|
- "int_cast_to_i64",
|
|
- i);
|
|
+ CastInst *shift = CastInst::CreateIntegerCast(
|
|
+ i->getOperand(1), Type::getInt64Ty(getGlobalContext()),
|
|
+ false, /* sign doesn't matter */
|
|
+ "int_cast_to_i64",
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ static_cast<Instruction *>(i));
|
|
+#else
|
|
+ i);
|
|
+#endif
|
|
args.push_back(shift);
|
|
|
|
|
|
diff --git a/lib/Module/InstructionInfoTable.cpp b/lib/Module/InstructionInfoTable.cpp
|
|
index 53c64878391f..52238786f49e 100644
|
|
--- a/lib/Module/InstructionInfoTable.cpp
|
|
+++ b/lib/Module/InstructionInfoTable.cpp
|
|
@@ -134,7 +134,12 @@ InstructionInfoTable::InstructionInfoTable(Module *m)
|
|
// if any.
|
|
const std::string *initialFile = &dummyString;
|
|
unsigned initialLine = 0;
|
|
- for (inst_iterator it = inst_begin(fnIt), ie = inst_end(fnIt); it != ie;
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ Function *fn = static_cast<Function *>(fnIt);
|
|
+#else
|
|
+ Function *fn = fnIt;
|
|
+#endif
|
|
+ for (inst_iterator it = inst_begin(fn), ie = inst_end(fn); it != ie;
|
|
++it) {
|
|
if (getInstructionDebugInfo(&*it, initialFile, initialLine))
|
|
break;
|
|
@@ -142,8 +147,8 @@ InstructionInfoTable::InstructionInfoTable(Module *m)
|
|
|
|
const std::string *file = initialFile;
|
|
unsigned line = initialLine;
|
|
- for (inst_iterator it = inst_begin(fnIt), ie = inst_end(fnIt); it != ie;
|
|
- ++it) {
|
|
+ for (inst_iterator it = inst_begin(fn), ie = inst_end(fn); it != ie;
|
|
+ ++it) {
|
|
Instruction *instr = &*it;
|
|
unsigned assemblyLine = lineTable[instr];
|
|
|
|
@@ -199,6 +204,10 @@ InstructionInfoTable::getFunctionInfo(const Function *f) const {
|
|
// and construct a test case for it if it does, though.
|
|
return dummyInfo;
|
|
} else {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ return getInfo(static_cast<const Instruction *>(f->begin()->begin()));
|
|
+#else
|
|
return getInfo(f->begin()->begin());
|
|
+#endif
|
|
}
|
|
}
|
|
diff --git a/lib/Module/IntrinsicCleaner.cpp b/lib/Module/IntrinsicCleaner.cpp
|
|
index 66e9392a618d..8ec47195dd3b 100644
|
|
--- a/lib/Module/IntrinsicCleaner.cpp
|
|
+++ b/lib/Module/IntrinsicCleaner.cpp
|
|
@@ -79,8 +79,12 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) {
|
|
for (BasicBlock::iterator i = b.begin(), ie = b.end();
|
|
(i != ie) && (block_split == false);) {
|
|
IntrinsicInst *ii = dyn_cast<IntrinsicInst>(&*i);
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ // create a copy of iterator to pass to IRBuilder ctor later
|
|
+ BasicBlock::iterator i_ = i;
|
|
+#endif
|
|
// increment now since LowerIntrinsic deletion makes iterator invalid.
|
|
- ++i;
|
|
+ ++i;
|
|
if(ii) {
|
|
switch (ii->getIntrinsicID()) {
|
|
case Intrinsic::vastart:
|
|
@@ -141,8 +145,12 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) {
|
|
case Intrinsic::uadd_with_overflow:
|
|
case Intrinsic::usub_with_overflow:
|
|
case Intrinsic::umul_with_overflow: {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ // ctor needs the iterator, but we already increased our one
|
|
+ IRBuilder<> builder(ii->getParent(), i_);
|
|
+#else
|
|
IRBuilder<> builder(ii->getParent(), ii);
|
|
-
|
|
+#endif
|
|
Value *op1 = ii->getArgOperand(0);
|
|
Value *op2 = ii->getArgOperand(1);
|
|
|
|
diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp
|
|
index cc328b1bb974..75e92804c91d 100644
|
|
--- a/lib/Module/KModule.cpp
|
|
+++ b/lib/Module/KModule.cpp
|
|
@@ -120,12 +120,15 @@ KModule::~KModule() {
|
|
delete[] constantTable;
|
|
delete infos;
|
|
|
|
- for (std::vector<KFunction*>::iterator it = functions.begin(),
|
|
- ie = functions.end(); it != ie; ++it)
|
|
+ for (std::vector<KFunction *>::iterator it = functions.begin(),
|
|
+ ie = functions.end();
|
|
+ it != ie; ++it)
|
|
delete *it;
|
|
|
|
- for (std::map<llvm::Constant*, KConstant*>::iterator it=constantMap.begin(),
|
|
- itE=constantMap.end(); it!=itE;++it)
|
|
+ for (std::map<llvm::Constant *, KConstant *>::iterator
|
|
+ it = constantMap.begin(),
|
|
+ itE = constantMap.end();
|
|
+ it != itE; ++it)
|
|
delete it->second;
|
|
|
|
delete targetData;
|
|
@@ -197,8 +200,14 @@ static void injectStaticConstructorsAndDestructors(Module *m) {
|
|
klee_error("Could not find main() function.");
|
|
|
|
if (ctors)
|
|
- CallInst::Create(getStubFunctionForCtorList(m, ctors, "klee.ctor_stub"),
|
|
- "", mainFn->begin()->begin());
|
|
+ CallInst::Create(getStubFunctionForCtorList(m, ctors, "klee.ctor_stub"),
|
|
+ "",
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ static_cast<Instruction *>(mainFn->begin()->begin()));
|
|
+#else
|
|
+ mainFn->begin()->begin());
|
|
+#endif
|
|
+
|
|
if (dtors) {
|
|
Function *dtorStub = getStubFunctionForCtorList(m, dtors, "klee.dtor_stub");
|
|
for (Function::iterator it = mainFn->begin(), ie = mainFn->end();
|
|
@@ -278,22 +287,27 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts,
|
|
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 0)
|
|
result = PHINode::Create(f->getReturnType(), 0, "retval", exit);
|
|
#else
|
|
- result = PHINode::Create(f->getReturnType(), "retval", exit);
|
|
+ result = PHINode::Create(f->getReturnType(), "retval", exit);
|
|
#endif
|
|
CallInst::Create(mergeFn, "", exit);
|
|
ReturnInst::Create(getGlobalContext(), result, exit);
|
|
|
|
llvm::errs() << "KLEE: adding klee_merge at exit of: " << name << "\n";
|
|
- for (llvm::Function::iterator bbit = f->begin(), bbie = f->end();
|
|
+ for (llvm::Function::iterator bbit = f->begin(), bbie = f->end();
|
|
bbit != bbie; ++bbit) {
|
|
- if (&*bbit != exit) {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ BasicBlock *bb = static_cast<BasicBlock *>(bbit);
|
|
+#else
|
|
+ BasicBlock *bb = bbit;
|
|
+#endif
|
|
+ if (bb != exit) {
|
|
Instruction *i = bbit->getTerminator();
|
|
if (i->getOpcode()==Instruction::Ret) {
|
|
if (result) {
|
|
- result->addIncoming(i->getOperand(0), bbit);
|
|
+ result->addIncoming(i->getOperand(0), bb);
|
|
}
|
|
i->eraseFromParent();
|
|
- BranchInst::Create(exit, bbit);
|
|
+ BranchInst::Create(exit, bb);
|
|
}
|
|
}
|
|
}
|
|
@@ -458,15 +472,20 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts,
|
|
if (it->isDeclaration())
|
|
continue;
|
|
|
|
- KFunction *kf = new KFunction(it, this);
|
|
-
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ Function *fn = static_cast<Function *>(it);
|
|
+#else
|
|
+ Function *fn = it;
|
|
+#endif
|
|
+ KFunction *kf = new KFunction(fn, this);
|
|
+
|
|
for (unsigned i=0; i<kf->numInstructions; ++i) {
|
|
KInstruction *ki = kf->instructions[i];
|
|
ki->info = &infos->getInfo(ki->inst);
|
|
}
|
|
|
|
functions.push_back(kf);
|
|
- functionMap.insert(std::make_pair(it, kf));
|
|
+ functionMap.insert(std::make_pair(fn, kf));
|
|
}
|
|
|
|
/* Compute various interesting properties */
|
|
@@ -547,7 +566,11 @@ KFunction::KFunction(llvm::Function *_function,
|
|
trackCoverage(true) {
|
|
for (llvm::Function::iterator bbit = function->begin(),
|
|
bbie = function->end(); bbit != bbie; ++bbit) {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ BasicBlock *bb = static_cast<BasicBlock *>(bbit);
|
|
+#else
|
|
BasicBlock *bb = bbit;
|
|
+#endif
|
|
basicBlockEntry[bb] = numInstructions;
|
|
numInstructions += bb->size();
|
|
}
|
|
@@ -562,7 +585,11 @@ KFunction::KFunction(llvm::Function *_function,
|
|
bbie = function->end(); bbit != bbie; ++bbit) {
|
|
for (llvm::BasicBlock::iterator it = bbit->begin(), ie = bbit->end();
|
|
it != ie; ++it)
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ registerMap[static_cast<Instruction *>(it)] = rnum++;
|
|
+#else
|
|
registerMap[it] = rnum++;
|
|
+#endif
|
|
}
|
|
numRegisters = rnum;
|
|
|
|
@@ -581,12 +608,16 @@ KFunction::KFunction(llvm::Function *_function,
|
|
default:
|
|
ki = new KInstruction(); break;
|
|
}
|
|
-
|
|
- ki->inst = it;
|
|
- ki->dest = registerMap[it];
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ Instruction *inst = static_cast<Instruction *>(it);
|
|
+#else
|
|
+ Instruction *inst = it;
|
|
+#endif
|
|
+ ki->inst = inst;
|
|
+ ki->dest = registerMap[inst];
|
|
|
|
if (isa<CallInst>(it) || isa<InvokeInst>(it)) {
|
|
- CallSite cs(it);
|
|
+ CallSite cs(inst);
|
|
unsigned numArgs = cs.arg_size();
|
|
ki->operands = new int[numArgs+1];
|
|
ki->operands[0] = getOperandNum(cs.getCalledValue(), registerMap, km,
|
|
diff --git a/lib/Module/LowerSwitch.cpp b/lib/Module/LowerSwitch.cpp
|
|
index a98b84add5d7..7cdd5fba2bf8 100644
|
|
--- a/lib/Module/LowerSwitch.cpp
|
|
+++ b/lib/Module/LowerSwitch.cpp
|
|
@@ -44,7 +44,12 @@ bool LowerSwitchPass::runOnFunction(Function &F) {
|
|
bool changed = false;
|
|
|
|
for (Function::iterator I = F.begin(), E = F.end(); I != E; ) {
|
|
- BasicBlock *cur = I++; // Advance over block so we don't traverse new blocks
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ BasicBlock *cur = static_cast<BasicBlock *>(I);
|
|
+#else
|
|
+ BasicBlock *cur = I;
|
|
+#endif
|
|
+ I++; // Advance over block so we don't traverse new blocks
|
|
|
|
if (SwitchInst *SI = dyn_cast<SwitchInst>(cur->getTerminator())) {
|
|
changed = true;
|
|
@@ -67,7 +72,11 @@ void LowerSwitchPass::switchConvert(CaseItr begin, CaseItr end,
|
|
// iterate through all the cases, creating a new BasicBlock for each
|
|
for (CaseItr it = begin; it < end; ++it) {
|
|
BasicBlock *newBlock = BasicBlock::Create(getGlobalContext(), "NodeBlock");
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ Function::iterator FI = origBlock->getIterator();
|
|
+#else
|
|
Function::iterator FI = origBlock;
|
|
+#endif
|
|
F->getBasicBlockList().insert(++FI, newBlock);
|
|
|
|
ICmpInst *cmpInst =
|
|
@@ -104,7 +113,11 @@ void LowerSwitchPass::processSwitchInst(SwitchInst *SI) {
|
|
// if-then statements go to this and the PHI nodes are happy.
|
|
BasicBlock* newDefault = BasicBlock::Create(getGlobalContext(), "newDefault");
|
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ F->getBasicBlockList().insert(defaultBlock->getIterator(), newDefault);
|
|
+#else
|
|
F->getBasicBlockList().insert(defaultBlock, newDefault);
|
|
+#endif
|
|
BranchInst::Create(defaultBlock, newDefault);
|
|
|
|
// If there is an entry in any PHI nodes for the default edge, make sure
|
|
diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp
|
|
index 2aa9b8e6b0ab..1e62498dc845 100644
|
|
--- a/lib/Module/ModuleUtil.cpp
|
|
+++ b/lib/Module/ModuleUtil.cpp
|
|
@@ -217,42 +217,59 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
|
AE = archive->child_end();
|
|
AI != AE; ++AI)
|
|
#else
|
|
-
|
|
for (object::Archive::child_iterator AI = archive->begin_children(),
|
|
AE = archive->end_children();
|
|
AI != AE; ++AI)
|
|
#endif
|
|
{
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
|
+ std::error_code ec;
|
|
+#else
|
|
+ error_code ec;
|
|
+#endif
|
|
StringRef memberName;
|
|
+
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ ErrorOr<object::Archive::Child> child = *AI;
|
|
+ ec = child.getError();
|
|
+ if (ec) {
|
|
+ errorMessage = ec.message();
|
|
+ return false;
|
|
+ }
|
|
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
|
+ object::Archive::child_iterator child = AI;
|
|
+#endif
|
|
+
|
|
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
|
- ErrorOr<StringRef> errorOr_memberName = AI->getName();
|
|
- std::error_code ec = errorOr_memberName.getError();
|
|
+ ErrorOr<StringRef> errorOr_memberName = child->getName();
|
|
+ ec = errorOr_memberName.getError();
|
|
if (!ec)
|
|
memberName = errorOr_memberName.get();
|
|
-#else
|
|
- error_code ec = AI->getName(memberName);
|
|
+#else // LLVM 3.3, 3.4
|
|
+ ec = AI->getName(memberName);
|
|
#endif
|
|
if (!ec) {
|
|
KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Loading archive member " << memberName << "\n");
|
|
} else {
|
|
- errorMessage="Archive member does not have a name!\n";
|
|
+ errorMessage = "Archive member does not have a name!";
|
|
return false;
|
|
}
|
|
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
|
- ErrorOr<std::unique_ptr<llvm::object::Binary> > child = AI->getAsBinary();
|
|
- ec = child.getError();
|
|
+ ErrorOr<std::unique_ptr<llvm::object::Binary> > childBin =
|
|
+ child->getAsBinary();
|
|
+ ec = childBin.getError();
|
|
#else
|
|
- OwningPtr<object::Binary> child;
|
|
- ec = AI->getAsBinary(child);
|
|
+ OwningPtr<object::Binary> childBin;
|
|
+ ec = AI->getAsBinary(childBin);
|
|
#endif
|
|
if (ec) {
|
|
// If we can't open as a binary object file its hopefully a bitcode file
|
|
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
|
|
- ErrorOr<MemoryBufferRef> buff = AI->getMemoryBufferRef();
|
|
+ ErrorOr<MemoryBufferRef> buff = child->getMemoryBufferRef();
|
|
ec = buff.getError();
|
|
#elif LLVM_VERSION_CODE == LLVM_VERSION(3, 5)
|
|
ErrorOr<std::unique_ptr<MemoryBuffer> > errorOr_buff =
|
|
- AI->getMemoryBuffer();
|
|
+ child->getMemoryBuffer();
|
|
std::unique_ptr<MemoryBuffer> buff = nullptr;
|
|
ec = errorOr_buff.getError();
|
|
if (!ec)
|
|
@@ -292,7 +309,7 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
|
ParseBitcodeFile(buff.get(), getGlobalContext(), &errorMessage);
|
|
#endif
|
|
if (!Result) {
|
|
- SS << "Loading module failed : " << errorMessage << "\n";
|
|
+ SS << "Loading module failed : " << errorMessage;
|
|
SS.flush();
|
|
return false;
|
|
}
|
|
@@ -301,8 +318,8 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
|
errorMessage = "Buffer was NULL!";
|
|
return false;
|
|
}
|
|
- } else if (child.get()->isObject()) {
|
|
- SS << "Object file " << child.get()->getFileName().data()
|
|
+ } else if (childBin.get()->isObject()) {
|
|
+ SS << "Object file " << childBin.get()->getFileName().data()
|
|
<< " in archive is not supported";
|
|
SS.flush();
|
|
return false;
|
|
@@ -346,7 +363,9 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
|
|
|
KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Found " << GV->getName() <<
|
|
" in " << M->getModuleIdentifier() << "\n");
|
|
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ if (Linker::linkModules(*composite, std::unique_ptr<Module>(M)))
|
|
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
|
|
if (Linker::LinkModules(composite, M))
|
|
#else
|
|
if (Linker::LinkModules(composite, M, Linker::DestroySource,
|
|
@@ -364,8 +383,10 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
|
// Link succeed, now clean up
|
|
modulesLoadedOnPass++;
|
|
KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Linking succeeded.\n");
|
|
-
|
|
+// M was owned by linkModules function
|
|
+#if LLVM_VERSION_CODE < LLVM_VERSION(3, 8)
|
|
delete M;
|
|
+#endif
|
|
archiveModules[i] = 0;
|
|
|
|
// We need to recompute the undefined symbols in the composite module
|
|
@@ -426,8 +447,12 @@ Module *klee::linkWithLibrary(Module *module,
|
|
|
|
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
|
|
ErrorOr<std::unique_ptr<Module> > Result = parseBitcodeFile(buff, Context);
|
|
-
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ if ((ec = Buffer.getError()) ||
|
|
+ Linker::linkModules(*module, std::move(Result.get())))
|
|
+#else
|
|
if ((ec = Buffer.getError()) || Linker::LinkModules(module, Result->get()))
|
|
+#endif
|
|
klee_error("Link with library %s failed: %s", libraryName.c_str(),
|
|
ec.message().c_str());
|
|
#else // LLVM 3.5, 3.6
|
|
@@ -487,7 +512,7 @@ Module *klee::linkWithLibrary(Module *module,
|
|
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
|
|
error_code ec;
|
|
OwningPtr<MemoryBuffer> Buffer;
|
|
- if (ec = MemoryBuffer::getFile(libraryName, Buffer)) {
|
|
+ if ((ec = MemoryBuffer::getFile(libraryName, Buffer))) {
|
|
klee_error("Link with library %s failed: %s", libraryName.c_str(),
|
|
ec.message().c_str());
|
|
}
|
|
@@ -510,7 +535,7 @@ Module *klee::linkWithLibrary(Module *module,
|
|
|
|
} else if (magic == sys::fs::file_magic::archive) {
|
|
OwningPtr<object::Binary> arch;
|
|
- if (ec = object::createBinary(Buffer.take(), arch))
|
|
+ if ((ec = object::createBinary(Buffer.take(), arch)))
|
|
klee_error("Link with library %s failed: %s", libraryName.c_str(),
|
|
ec.message().c_str());
|
|
|
|
diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp
|
|
index 3eca0db6c174..e6a6c35e9ce2 100644
|
|
--- a/lib/Module/Optimize.cpp
|
|
+++ b/lib/Module/Optimize.cpp
|
|
@@ -126,7 +126,12 @@ static void AddStandardCompilePasses(PassManager &PM) {
|
|
addPass(PM, createCFGSimplificationPass()); // Clean up after IPCP & DAE
|
|
|
|
addPass(PM, createPruneEHPass()); // Remove dead EH info
|
|
- addPass(PM, createFunctionAttrsPass()); // Deduce function attrs
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ addPass(PM, createPostOrderFunctionAttrsPass());
|
|
+ addPass(PM, createReversePostOrderFunctionAttrsPass());
|
|
+#else
|
|
+ addPass(PM, createFunctionAttrsPass()); // Deduce function attrs
|
|
+#endif
|
|
|
|
if (!DisableInline)
|
|
addPass(PM, createFunctionInliningPass()); // Inline small functions
|
|
@@ -258,8 +263,14 @@ void Optimize(Module *M, const std::string &EntryPoint) {
|
|
addPass(Passes, createScalarReplAggregatesPass()); // Break up allocas
|
|
|
|
// Run a few AA driven optimizations here and now, to cleanup the code.
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ addPass(Passes, createPostOrderFunctionAttrsPass());
|
|
+ addPass(Passes, createReversePostOrderFunctionAttrsPass());
|
|
+ // addPass(Passes, createGlobalsAAWrapperPass());
|
|
+#else
|
|
addPass(Passes, createFunctionAttrsPass()); // Add nocapture
|
|
addPass(Passes, createGlobalsModRefPass()); // IP alias analysis
|
|
+#endif
|
|
|
|
addPass(Passes, createLICMPass()); // Hoist loop invariants
|
|
addPass(Passes, createGVNPass()); // Remove redundancies
|
|
diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp
|
|
index a2972ce7ee9b..c820736f5d66 100644
|
|
--- a/lib/Module/RaiseAsm.cpp
|
|
+++ b/lib/Module/RaiseAsm.cpp
|
|
@@ -126,7 +126,11 @@ bool RaiseAsmPass::runOnModule(Module &M) {
|
|
for (Module::iterator fi = M.begin(), fe = M.end(); fi != fe; ++fi) {
|
|
for (Function::iterator bi = fi->begin(), be = fi->end(); bi != be; ++bi) {
|
|
for (BasicBlock::iterator ii = bi->begin(), ie = bi->end(); ii != ie;) {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ auto i = static_cast<Instruction *>(ii);
|
|
+#else
|
|
Instruction *i = ii;
|
|
+#endif
|
|
++ii;
|
|
changed |= runOnInstruction(M, i);
|
|
}
|
|
diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp
|
|
index 9265abe04820..80af2c253997 100644
|
|
--- a/tools/klee/main.cpp
|
|
+++ b/tools/klee/main.cpp
|
|
@@ -313,7 +313,12 @@ KleeHandler::KleeHandler(int argc, char **argv)
|
|
for (; i <= INT_MAX; ++i) {
|
|
SmallString<128> d(directory);
|
|
llvm::sys::path::append(d, "klee-out-");
|
|
- raw_svector_ostream ds(d); ds << i; ds.flush();
|
|
+ raw_svector_ostream ds(d);
|
|
+ ds << i;
|
|
+// SmallString is always up-to-date, no need to flush. See Support/raw_ostream.h
|
|
+#if LLVM_VERSION_CODE < LLVM_VERSION(3, 8)
|
|
+ ds.flush();
|
|
+#endif
|
|
|
|
// create directory and try to link klee-last
|
|
if (mkdir(d.c_str(), 0775) == 0) {
|
|
@@ -690,11 +695,17 @@ static int initEnv(Module *mainModule) {
|
|
if (mainFn->arg_size() < 2) {
|
|
klee_error("Cannot handle ""--posix-runtime"" when main() has less than two arguments.\n");
|
|
}
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ auto firstInst = static_cast<Instruction *>(mainFn->begin()->begin());
|
|
|
|
- Instruction* firstInst = mainFn->begin()->begin();
|
|
+ auto oldArgc = static_cast<Argument *>(mainFn->arg_begin());
|
|
+ auto oldArgv = static_cast<Argument *>(++mainFn->arg_begin());
|
|
+#else
|
|
+ Instruction *firstInst = mainFn->begin()->begin();
|
|
|
|
- Value* oldArgc = mainFn->arg_begin();
|
|
- Value* oldArgv = ++mainFn->arg_begin();
|
|
+ Value *oldArgc = mainFn->arg_begin();
|
|
+ Value *oldArgv = ++mainFn->arg_begin();
|
|
+#endif
|
|
|
|
AllocaInst* argcPtr =
|
|
new AllocaInst(oldArgc->getType(), "argcPtr", firstInst);
|
|
@@ -1099,7 +1110,11 @@ static llvm::Module *linkWithUclibc(llvm::Module *mainModule, StringRef libDir)
|
|
// naming conflict.
|
|
for (Module::iterator fi = mainModule->begin(), fe = mainModule->end();
|
|
fi != fe; ++fi) {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ auto f = static_cast<Function *>(fi);
|
|
+#else
|
|
Function *f = fi;
|
|
+#endif
|
|
const std::string &name = f->getName();
|
|
if (name[0]=='\01') {
|
|
unsigned size = name.size();
|
|
@@ -1158,8 +1173,13 @@ static llvm::Module *linkWithUclibc(llvm::Module *mainModule, StringRef libDir)
|
|
std::vector<llvm::Value*> args;
|
|
args.push_back(llvm::ConstantExpr::getBitCast(userMainFn,
|
|
ft->getParamType(0)));
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ args.push_back(static_cast<Argument *>(stub->arg_begin())); // argc
|
|
+ args.push_back(static_cast<Argument *>(++stub->arg_begin())); // argv
|
|
+#else
|
|
args.push_back(stub->arg_begin()); // argc
|
|
args.push_back(++stub->arg_begin()); // argv
|
|
+#endif
|
|
args.push_back(Constant::getNullValue(ft->getParamType(3))); // app_init
|
|
args.push_back(Constant::getNullValue(ft->getParamType(4))); // app_fini
|
|
args.push_back(Constant::getNullValue(ft->getParamType(5))); // rtld_fini
|
|
@@ -1301,7 +1321,11 @@ int main(int argc, char **argv, char **envp) {
|
|
#else
|
|
mainModule = *mainModuleOrError;
|
|
#endif
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+ if (auto ec = mainModule->materializeAll()) {
|
|
+#else
|
|
if (auto ec = mainModule->materializeAllPermanently()) {
|
|
+#endif
|
|
klee_error("error loading program '%s': %s", InputFile.c_str(),
|
|
ec.message().c_str());
|
|
}
|
|
--
|
|
2.11.1
|
|
|