OBS-URL: https://build.opensuse.org/package/show/devel:tools:statica/klee?expand=0&rev=24
296 lines
11 KiB
Diff
296 lines
11 KiB
Diff
From: Jiri Slaby <jirislaby@gmail.com>
|
|
Date: Wed, 22 Feb 2017 15:57:55 +0100
|
|
Subject: llvm: make KLEE compile against LLVM 3.9
|
|
Patch-mainline: no
|
|
|
|
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
|
|
---
|
|
lib/Core/Executor.cpp | 16 ++++++++++++++++
|
|
lib/Core/MemoryManager.cpp | 5 ++++-
|
|
lib/Module/ModuleUtil.cpp | 33 ++++++++++++++++++++++++++++++---
|
|
lib/Module/Optimize.cpp | 29 ++++++++++++++++++++++++++++-
|
|
lib/Module/RaiseAsm.cpp | 11 +++++++++--
|
|
tools/kleaver/main.cpp | 4 ++++
|
|
tools/klee/main.cpp | 4 ++++
|
|
7 files changed, 95 insertions(+), 7 deletions(-)
|
|
|
|
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
|
|
index 70354edc37ea..841734573abc 100644
|
|
--- a/lib/Core/Executor.cpp
|
|
+++ b/lib/Core/Executor.cpp
|
|
@@ -1399,10 +1399,18 @@ void Executor::executeCall(ExecutionState &state,
|
|
//
|
|
// Alignment requirements for scalar types is the same as their size
|
|
if (argWidth > Expr::Int64) {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ size = llvm::alignTo(size, 16);
|
|
+#else
|
|
size = llvm::RoundUpToAlignment(size, 16);
|
|
+#endif
|
|
requires16ByteAlignment = true;
|
|
}
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ size += llvm::alignTo(argWidth, WordSize) / 8;
|
|
+#else
|
|
size += llvm::RoundUpToAlignment(argWidth, WordSize) / 8;
|
|
+#endif
|
|
}
|
|
}
|
|
|
|
@@ -1435,10 +1443,18 @@ void Executor::executeCall(ExecutionState &state,
|
|
|
|
Expr::Width argWidth = arguments[i]->getWidth();
|
|
if (argWidth > Expr::Int64) {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ offset = llvm::alignTo(offset, 16);
|
|
+#else
|
|
offset = llvm::RoundUpToAlignment(offset, 16);
|
|
+#endif
|
|
}
|
|
os->write(offset, arguments[i]);
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ offset += llvm::alignTo(argWidth, WordSize) / 8;
|
|
+#else
|
|
offset += llvm::RoundUpToAlignment(argWidth, WordSize) / 8;
|
|
+#endif
|
|
}
|
|
}
|
|
}
|
|
diff --git a/lib/Core/MemoryManager.cpp b/lib/Core/MemoryManager.cpp
|
|
index 24e2ed97581f..f40e8bc9deb8 100644
|
|
--- a/lib/Core/MemoryManager.cpp
|
|
+++ b/lib/Core/MemoryManager.cpp
|
|
@@ -111,9 +111,12 @@ MemoryObject *MemoryManager::allocate(uint64_t size, bool isLocal,
|
|
|
|
uint64_t address = 0;
|
|
if (DeterministicAllocation) {
|
|
-
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ address = llvm::alignTo((uint64_t)nextFreeSlot + alignment - 1, alignment);
|
|
+#else
|
|
address = llvm::RoundUpToAlignment((uint64_t)nextFreeSlot + alignment - 1,
|
|
alignment);
|
|
+#endif
|
|
|
|
// Handle the case of 0-sized allocations as 1-byte allocations.
|
|
// This way, we make sure we have this allocation between its own red zones
|
|
diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp
|
|
index 6b50b037bc65..14d48b026d14 100644
|
|
--- a/lib/Module/ModuleUtil.cpp
|
|
+++ b/lib/Module/ModuleUtil.cpp
|
|
@@ -212,7 +212,11 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
|
|
|
KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Loading modules\n");
|
|
// Load all bitcode files in to memory so we can examine their symbols
|
|
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ Error Err;
|
|
+ for (object::Archive::child_iterator AI = archive->child_begin(Err),
|
|
+ AE = archive->child_end(); AI != AE; ++AI)
|
|
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
|
for (object::Archive::child_iterator AI = archive->child_begin(),
|
|
AE = archive->child_end(); AI != AE; ++AI)
|
|
#else
|
|
@@ -252,7 +256,14 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
|
return false;
|
|
}
|
|
|
|
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ Expected<std::unique_ptr<llvm::object::Binary> > child =
|
|
+ childErr->getAsBinary();
|
|
+ if (!child) {
|
|
+ ec = errorToErrorCode(child.takeError());
|
|
+ consumeError(child.takeError());
|
|
+ }
|
|
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
|
ErrorOr<std::unique_ptr<llvm::object::Binary> > child =
|
|
childErr->getAsBinary();
|
|
ec = child.getError();
|
|
@@ -335,6 +346,13 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
|
}
|
|
|
|
}
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ if (Err) {
|
|
+ SS << "Cannot iterate over archive";
|
|
+ SS.flush();
|
|
+ return false;
|
|
+ }
|
|
+#endif
|
|
|
|
KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Loaded " << archiveModules.size() << " modules\n");
|
|
|
|
@@ -505,7 +523,12 @@ Module *klee::linkWithLibrary(Module *module,
|
|
#endif
|
|
|
|
} else if (magic == sys::fs::file_magic::archive) {
|
|
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ Expected<std::unique_ptr<object::Binary> > arch =
|
|
+ object::createBinary(Buffer, &Context);
|
|
+ if (!arch)
|
|
+ ec = errorToErrorCode(arch.takeError());
|
|
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
|
|
ErrorOr<std::unique_ptr<object::Binary> > arch =
|
|
object::createBinary(Buffer, &Context);
|
|
ec = arch.getError();
|
|
@@ -575,7 +598,11 @@ Function *klee::getDirectCallTarget(CallSite cs, bool moduleIsFullyLinked) {
|
|
if (Function *f = dyn_cast<Function>(v)) {
|
|
return f;
|
|
} else if (llvm::GlobalAlias *ga = dyn_cast<GlobalAlias>(v)) {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ if (moduleIsFullyLinked || !(ga->isInterposable())) {
|
|
+#else
|
|
if (moduleIsFullyLinked || !(ga->mayBeOverridden())) {
|
|
+#endif
|
|
v = ga->getAliasee();
|
|
} else {
|
|
v = NULL;
|
|
diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp
|
|
index 46ab7d028224..745d89f70027 100644
|
|
--- a/lib/Module/Optimize.cpp
|
|
+++ b/lib/Module/Optimize.cpp
|
|
@@ -16,6 +16,9 @@
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "klee/Config/Version.h"
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+#include "llvm/Transforms/IPO/FunctionAttrs.h"
|
|
+#endif
|
|
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
|
|
#include "llvm/IR/LegacyPassManager.h"
|
|
#else
|
|
@@ -47,6 +50,9 @@
|
|
#include "llvm/Target/TargetMachine.h"
|
|
#include "llvm/Transforms/IPO.h"
|
|
#include "llvm/Transforms/Scalar.h"
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+#include "llvm/Transforms/Scalar/GVN.h"
|
|
+#endif
|
|
#include "llvm/Support/PluginLoader.h"
|
|
using namespace llvm;
|
|
|
|
@@ -127,7 +133,11 @@ static void AddStandardCompilePasses(PassManager &PM) {
|
|
|
|
addPass(PM, createPruneEHPass()); // Remove dead EH info
|
|
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ addPass(PM, createPostOrderFunctionAttrsLegacyPass());
|
|
+#else
|
|
addPass(PM, createPostOrderFunctionAttrsPass());
|
|
+#endif
|
|
addPass(PM, createReversePostOrderFunctionAttrsPass());
|
|
#else
|
|
addPass(PM, createFunctionAttrsPass()); // Deduce function attrs
|
|
@@ -143,7 +153,11 @@ static void AddStandardCompilePasses(PassManager &PM) {
|
|
addPass(PM, createInstructionCombiningPass()); // Cleanup for scalarrepl.
|
|
addPass(PM, createJumpThreadingPass()); // Thread jumps.
|
|
addPass(PM, createCFGSimplificationPass()); // Merge & remove BBs
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ addPass(PM, createSROAPass()); // Break up aggregate allocas
|
|
+#else
|
|
addPass(PM, createScalarReplAggregatesPass()); // Break up aggregate allocas
|
|
+#endif
|
|
addPass(PM, createInstructionCombiningPass()); // Combine silly seq's
|
|
|
|
addPass(PM, createTailCallEliminationPass()); // Eliminate tail calls
|
|
@@ -215,7 +229,12 @@ void Optimize(Module *M, const std::string &EntryPoint) {
|
|
// for a main function. If main is defined, mark all other functions
|
|
// internal.
|
|
if (!DisableInternalize) {
|
|
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 2)
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ auto PreserveEP = [=](const GlobalValue &GV) {
|
|
+ return GV.getName().equals(EntryPoint);
|
|
+ };
|
|
+ ModulePass *pass = createInternalizePass(PreserveEP);
|
|
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 2)
|
|
ModulePass *pass = createInternalizePass(
|
|
std::vector<const char *>(1, EntryPoint.c_str()));
|
|
#else
|
|
@@ -259,11 +278,19 @@ void Optimize(Module *M, const std::string &EntryPoint) {
|
|
// The IPO passes may leave cruft around. Clean up after them.
|
|
addPass(Passes, createInstructionCombiningPass());
|
|
addPass(Passes, createJumpThreadingPass()); // Thread jumps.
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ addPass(Passes, createSROAPass()); // Break up allocas
|
|
+#else
|
|
addPass(Passes, createScalarReplAggregatesPass()); // Break up allocas
|
|
+#endif
|
|
|
|
// Run a few AA driven optimizations here and now, to cleanup the code.
|
|
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ addPass(Passes, createPostOrderFunctionAttrsLegacyPass());
|
|
+#else
|
|
addPass(Passes, createPostOrderFunctionAttrsPass());
|
|
+#endif
|
|
addPass(Passes, createReversePostOrderFunctionAttrsPass());
|
|
// addPass(Passes, createGlobalsAAWrapperPass());
|
|
#else
|
|
diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp
|
|
index 668ce4853cca..08e78748d30c 100644
|
|
--- a/lib/Module/RaiseAsm.cpp
|
|
+++ b/lib/Module/RaiseAsm.cpp
|
|
@@ -75,7 +75,10 @@ bool RaiseAsmPass::runOnInstruction(Module &M, Instruction *I) {
|
|
triple.getOS() == llvm::Triple::Darwin)) {
|
|
|
|
if (ia->getAsmString() == "" && ia->hasSideEffects()) {
|
|
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ IRBuilder<> Builder(I);
|
|
+ Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent);
|
|
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
|
|
IRBuilder<> Builder(I);
|
|
Builder.CreateFence(llvm::SequentiallyConsistent);
|
|
#endif
|
|
@@ -103,7 +106,11 @@ bool RaiseAsmPass::runOnModule(Module &M) {
|
|
klee_warning("Warning: unable to select native target: %s", Err.c_str());
|
|
TLI = 0;
|
|
} else {
|
|
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ TM = NativeTarget->createTargetMachine(HostTriple, "", "", TargetOptions(),
|
|
+ None);
|
|
+ TLI = TM->getSubtargetImpl(*(M.begin()))->getTargetLowering();
|
|
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
|
|
TM = NativeTarget->createTargetMachine(HostTriple, "", "", TargetOptions());
|
|
TLI = TM->getSubtargetImpl(*(M.begin()))->getTargetLowering();
|
|
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
|
|
diff --git a/tools/kleaver/main.cpp b/tools/kleaver/main.cpp
|
|
index b8b32e31264a..800cece95e9c 100644
|
|
--- a/tools/kleaver/main.cpp
|
|
+++ b/tools/kleaver/main.cpp
|
|
@@ -400,7 +400,11 @@ static bool printInputAsSMTLIBv2(const char *Filename,
|
|
int main(int argc, char **argv) {
|
|
bool success = true;
|
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
|
|
+#else
|
|
llvm::sys::PrintStackTraceOnErrorSignal();
|
|
+#endif
|
|
llvm::cl::SetVersionPrinter(klee::printVersion);
|
|
llvm::cl::ParseCommandLineOptions(argc, argv);
|
|
|
|
diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp
|
|
index 78ea1a6eb569..eac69ada30e0 100644
|
|
--- a/tools/klee/main.cpp
|
|
+++ b/tools/klee/main.cpp
|
|
@@ -1170,7 +1170,11 @@ int main(int argc, char **argv, char **envp) {
|
|
llvm::InitializeNativeTarget();
|
|
|
|
parseArguments(argc, argv);
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
+ sys::PrintStackTraceOnErrorSignal(argv[0]);
|
|
+#else
|
|
sys::PrintStackTraceOnErrorSignal();
|
|
+#endif
|
|
|
|
if (Watchdog) {
|
|
if (MaxTime==0) {
|
|
--
|
|
2.13.1
|
|
|