2017-02-13 12:09:45 +00:00
|
|
|
From: =?UTF-8?q?Richard=20Trembeck=C3=BD?= <richardt@centrum.sk>
|
|
|
|
Date: Wed, 4 May 2016 15:21:45 +0200
|
2017-03-16 16:19:41 +00:00
|
|
|
Subject: llvm: make KLEE compile against LLVM 3.8
|
2017-02-13 12:09:45 +00:00
|
|
|
Patch-mainline: no
|
|
|
|
|
2017-03-16 16:19:41 +00:00
|
|
|
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
|
2017-02-13 12:09:45 +00:00
|
|
|
---
|
2017-03-16 16:19:41 +00:00
|
|
|
lib/Core/Executor.cpp | 5 +++++
|
|
|
|
lib/Core/StatsTracker.cpp | 4 ++++
|
|
|
|
lib/Module/IntrinsicCleaner.cpp | 10 +++++++++-
|
|
|
|
lib/Module/LowerSwitch.cpp | 8 ++++++++
|
2017-08-17 12:28:29 +00:00
|
|
|
lib/Module/ModuleUtil.cpp | 39 +++++++++++++++++++++++++++++++++------
|
2017-03-16 16:19:41 +00:00
|
|
|
lib/Module/Optimize.cpp | 13 ++++++++++++-
|
2017-08-17 12:28:29 +00:00
|
|
|
tools/klee/main.cpp | 7 ++++++-
|
|
|
|
7 files changed, 77 insertions(+), 9 deletions(-)
|
2017-02-13 12:09:45 +00:00
|
|
|
|
|
|
|
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
|
2018-01-15 11:59:55 +00:00
|
|
|
index 045e353ba932..96d85f503d4f 100644
|
2017-02-13 12:09:45 +00:00
|
|
|
--- a/lib/Core/Executor.cpp
|
|
|
|
+++ b/lib/Core/Executor.cpp
|
2018-01-15 11:59:55 +00:00
|
|
|
@@ -2135,8 +2135,13 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
|
2017-08-17 12:28:29 +00:00
|
|
|
!fpWidthToSemantics(right->getWidth()))
|
2017-02-13 12:09:45 +00:00
|
|
|
return terminateStateOnExecError(state, "Unsupported FRem operation");
|
|
|
|
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
|
2017-08-17 12:28:29 +00:00
|
|
|
bindLocal(ki, state, ConstantExpr::alloc(Res.bitcastToAPInt()));
|
|
|
|
break;
|
|
|
|
}
|
2017-02-13 12:09:45 +00:00
|
|
|
diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp
|
2017-10-10 13:09:53 +00:00
|
|
|
index 6dc13df86440..e931dcef8b2e 100644
|
2017-02-13 12:09:45 +00:00
|
|
|
--- a/lib/Core/StatsTracker.cpp
|
|
|
|
+++ b/lib/Core/StatsTracker.cpp
|
2017-10-10 13:09:53 +00:00
|
|
|
@@ -629,7 +629,11 @@ static std::vector<Instruction*> getSuccs(Instruction *i) {
|
2017-02-13 12:09:45 +00:00
|
|
|
for (succ_iterator it = succ_begin(bb), ie = succ_end(bb); it != ie; ++it)
|
2017-08-17 12:28:29 +00:00
|
|
|
res.push_back(&*(it->begin()));
|
2017-02-13 12:09:45 +00:00
|
|
|
} else {
|
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
2017-06-08 12:15:29 +00:00
|
|
|
+ res.push_back(&*(++(i->getIterator())));
|
2017-02-13 12:09:45 +00:00
|
|
|
+#else
|
2017-06-08 12:15:29 +00:00
|
|
|
res.push_back(&*(++BasicBlock::iterator(i)));
|
2017-02-13 12:09:45 +00:00
|
|
|
+#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
diff --git a/lib/Module/IntrinsicCleaner.cpp b/lib/Module/IntrinsicCleaner.cpp
|
2017-08-17 12:28:29 +00:00
|
|
|
index 54bda16013b6..2b93319f2615 100644
|
2017-02-13 12:09:45 +00:00
|
|
|
--- a/lib/Module/IntrinsicCleaner.cpp
|
|
|
|
+++ b/lib/Module/IntrinsicCleaner.cpp
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -52,6 +52,10 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) {
|
2017-02-13 12:09:45 +00:00
|
|
|
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.
|
2017-03-16 16:19:41 +00:00
|
|
|
++i;
|
2017-02-13 12:09:45 +00:00
|
|
|
if(ii) {
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -104,8 +108,12 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) {
|
2017-02-13 12:09:45 +00:00
|
|
|
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/LowerSwitch.cpp b/lib/Module/LowerSwitch.cpp
|
2018-01-15 11:59:55 +00:00
|
|
|
index 02f00a3ae94e..7fe9d9768d72 100644
|
2017-02-13 12:09:45 +00:00
|
|
|
--- a/lib/Module/LowerSwitch.cpp
|
|
|
|
+++ b/lib/Module/LowerSwitch.cpp
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -64,7 +64,11 @@ void LowerSwitchPass::switchConvert(CaseItr begin, CaseItr end,
|
2017-02-13 12:09:45 +00:00
|
|
|
// iterate through all the cases, creating a new BasicBlock for each
|
|
|
|
for (CaseItr it = begin; it < end; ++it) {
|
2017-03-16 16:19:41 +00:00
|
|
|
BasicBlock *newBlock = BasicBlock::Create(F->getContext(), "NodeBlock");
|
2017-02-13 12:09:45 +00:00
|
|
|
+#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 =
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -101,7 +105,11 @@ void LowerSwitchPass::processSwitchInst(SwitchInst *SI) {
|
2017-02-13 12:09:45 +00:00
|
|
|
// if-then statements go to this and the PHI nodes are happy.
|
2017-03-16 16:19:41 +00:00
|
|
|
BasicBlock* newDefault = BasicBlock::Create(F->getContext(), "newDefault");
|
2017-02-13 12:09:45 +00:00
|
|
|
|
|
|
|
+#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
|
2017-10-10 13:09:53 +00:00
|
|
|
index b07d3d2fe348..e6d592b135b6 100644
|
2017-02-13 12:09:45 +00:00
|
|
|
--- a/lib/Module/ModuleUtil.cpp
|
|
|
|
+++ b/lib/Module/ModuleUtil.cpp
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -207,8 +207,19 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
2017-03-16 16:19:41 +00:00
|
|
|
|
2017-02-13 12:09:45 +00:00
|
|
|
StringRef memberName;
|
2017-03-16 16:19:41 +00:00
|
|
|
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
|
|
|
- ErrorOr<StringRef> memberNameErr = AI->getName();
|
|
|
|
- std::error_code ec = memberNameErr.getError();
|
|
|
|
+ std::error_code ec;
|
2017-02-13 12:09:45 +00:00
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
2017-03-16 16:19:41 +00:00
|
|
|
+ ErrorOr<object::Archive::Child> childErr = *AI;
|
|
|
|
+ ec = childErr.getError();
|
2017-02-13 12:09:45 +00:00
|
|
|
+ if (ec) {
|
|
|
|
+ errorMessage = ec.message();
|
|
|
|
+ return false;
|
|
|
|
+ }
|
2017-03-16 16:19:41 +00:00
|
|
|
+#else
|
|
|
|
+ object::Archive::child_iterator childErr = AI;
|
2017-02-13 12:09:45 +00:00
|
|
|
+#endif
|
2017-03-16 16:19:41 +00:00
|
|
|
+ ErrorOr<StringRef> memberNameErr = childErr->getName();
|
|
|
|
+ ec = memberNameErr.getError();
|
2017-02-13 12:09:45 +00:00
|
|
|
if (!ec) {
|
2017-03-16 16:19:41 +00:00
|
|
|
memberName = memberNameErr.get();
|
|
|
|
#else
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -226,7 +237,8 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
2017-02-13 12:09:45 +00:00
|
|
|
}
|
2017-03-16 16:19:41 +00:00
|
|
|
|
2017-02-13 12:09:45 +00:00
|
|
|
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
|
|
|
- ErrorOr<std::unique_ptr<llvm::object::Binary> > child = AI->getAsBinary();
|
2017-03-16 16:19:41 +00:00
|
|
|
+ ErrorOr<std::unique_ptr<llvm::object::Binary> > child =
|
|
|
|
+ childErr->getAsBinary();
|
|
|
|
ec = child.getError();
|
2017-02-13 12:09:45 +00:00
|
|
|
#else
|
2017-03-16 16:19:41 +00:00
|
|
|
OwningPtr<object::Binary> child;
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -235,7 +247,7 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
2017-02-13 12:09:45 +00:00
|
|
|
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();
|
2017-03-16 16:19:41 +00:00
|
|
|
+ ErrorOr<MemoryBufferRef> buff = childErr->getMemoryBufferRef();
|
2017-02-13 12:09:45 +00:00
|
|
|
ec = buff.getError();
|
2017-03-16 16:19:41 +00:00
|
|
|
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
|
|
|
ErrorOr<std::unique_ptr<MemoryBuffer> > buffErr = AI->getMemoryBuffer();
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -343,7 +355,9 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
2017-02-13 12:09:45 +00:00
|
|
|
KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Found " << GV->getName() <<
|
|
|
|
" in " << M->getModuleIdentifier() << "\n");
|
2017-03-16 16:19:41 +00:00
|
|
|
|
2017-02-13 12:09:45 +00:00
|
|
|
-#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
|
2017-03-16 16:19:41 +00:00
|
|
|
if (Linker::LinkModules(composite, M, Linker::DestroySource, &errorMessage))
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -360,8 +374,10 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
2017-02-13 12:09:45 +00:00
|
|
|
// 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
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -427,7 +443,9 @@ Module *klee::linkWithLibrary(Module *module,
|
2017-03-16 16:19:41 +00:00
|
|
|
std::string ErrorMessage;
|
2017-02-13 12:09:45 +00:00
|
|
|
|
2017-03-16 16:19:41 +00:00
|
|
|
if (magic == sys::fs::file_magic::bitcode) {
|
|
|
|
+#if LLVM_VERSION_CODE < LLVM_VERSION(3, 8)
|
|
|
|
Module *Result = 0;
|
2017-02-13 12:09:45 +00:00
|
|
|
+#endif
|
2017-03-16 16:19:41 +00:00
|
|
|
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
|
|
|
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
|
|
|
|
ErrorOr<std::unique_ptr<Module> > ResultErr =
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -445,6 +463,10 @@ Module *klee::linkWithLibrary(Module *module,
|
2017-03-16 16:19:41 +00:00
|
|
|
ErrorMessage.c_str());
|
|
|
|
}
|
2017-02-13 12:09:45 +00:00
|
|
|
|
2017-03-16 16:19:41 +00:00
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
|
|
+ if (Linker::linkModules(*module, std::move(ResultErr.get()))) {
|
|
|
|
+ ErrorMessage = "linking error";
|
2017-08-17 12:28:29 +00:00
|
|
|
+#else
|
|
|
|
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
|
|
|
|
Result = ResultErr->release();
|
|
|
|
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
|
|
|
@@ -456,6 +478,7 @@ Module *klee::linkWithLibrary(Module *module,
|
2017-03-16 16:19:41 +00:00
|
|
|
ErrorMessage = "linking error";
|
|
|
|
#else
|
2017-08-17 12:28:29 +00:00
|
|
|
if (Linker::LinkModules(module, Result, Linker::DestroySource, &ErrorMessage)) {
|
|
|
|
+#endif
|
|
|
|
#endif
|
|
|
|
klee_error("Link with library %s failed: %s", libraryName.c_str(),
|
|
|
|
ErrorMessage.c_str());
|
2017-10-10 13:09:53 +00:00
|
|
|
@@ -639,7 +662,11 @@ Module *klee::loadModule(LLVMContext &ctx, const std::string &path, std::string
|
2017-08-17 12:28:29 +00:00
|
|
|
auto module = *errorOrModule;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
|
|
+ if (auto ec = module->materializeAll()) {
|
|
|
|
+#else
|
|
|
|
if (auto ec = module->materializeAllPermanently()) {
|
|
|
|
+#endif
|
|
|
|
errorMsg = ec.message();
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-02-13 12:09:45 +00:00
|
|
|
diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp
|
2017-08-17 12:28:29 +00:00
|
|
|
index 64e4863f70b3..944f51ef336d 100644
|
2017-02-13 12:09:45 +00:00
|
|
|
--- a/lib/Module/Optimize.cpp
|
|
|
|
+++ b/lib/Module/Optimize.cpp
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -102,7 +102,12 @@ static void AddStandardCompilePasses(klee::LegacyLLVMPassManagerTy &PM) {
|
2017-02-13 12:09:45 +00:00
|
|
|
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
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -217,8 +222,14 @@ void Optimize(Module *M, const std::string &EntryPoint) {
|
2017-02-13 12:09:45 +00:00
|
|
|
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/tools/klee/main.cpp b/tools/klee/main.cpp
|
2018-01-15 11:59:55 +00:00
|
|
|
index ea24d89c5aaf..14afce0edf7c 100644
|
2017-02-13 12:09:45 +00:00
|
|
|
--- a/tools/klee/main.cpp
|
|
|
|
+++ b/tools/klee/main.cpp
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -291,7 +291,12 @@ KleeHandler::KleeHandler(int argc, char **argv)
|
2017-02-13 12:09:45 +00:00
|
|
|
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) {
|
|
|
|
--
|
2018-01-15 11:59:55 +00:00
|
|
|
2.15.1
|
2017-02-13 12:09:45 +00:00
|
|
|
|