klee/0002-llvm-make-KLEE-compile-against-LLVM-3.7.patch

178 lines
6.7 KiB
Diff

From: =?UTF-8?q?Richard=20Trembeck=C3=BD?= <richardt@centrum.sk>
Date: Thu, 28 Apr 2016 18:27:24 +0200
Subject: llvm: make KLEE compile against LLVM 3.7
Patch-mainline: no
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
include/klee/Internal/Support/FloatEvaluation.h | 7 ++++++
lib/Module/InstructionInfoTable.cpp | 6 +++++
lib/Module/ModuleUtil.cpp | 30 +++++++++++++++++++++----
lib/Module/Optimize.cpp | 4 +++-
lib/Module/RaiseAsm.cpp | 5 ++++-
tools/klee/main.cpp | 1 +
6 files changed, 47 insertions(+), 6 deletions(-)
diff --git a/include/klee/Internal/Support/FloatEvaluation.h b/include/klee/Internal/Support/FloatEvaluation.h
index 6d9092f2ea37..436e0dc8152f 100644
--- a/include/klee/Internal/Support/FloatEvaluation.h
+++ b/include/klee/Internal/Support/FloatEvaluation.h
@@ -132,8 +132,15 @@ inline uint64_t mod(uint64_t l, uint64_t r, unsigned inWidth) {
// determine if l represents NaN
inline bool isNaN(uint64_t l, unsigned inWidth) {
switch( inWidth ) {
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+ case FLT_BITS:
+ return std::isnan(UInt64AsFloat(l));
+ case DBL_BITS:
+ return std::isnan(UInt64AsDouble(l));
+#else
case FLT_BITS: return llvm::IsNAN( UInt64AsFloat(l) );
case DBL_BITS: return llvm::IsNAN( UInt64AsDouble(l) );
+#endif
default: llvm::report_fatal_error("unsupported floating point width");
}
}
diff --git a/lib/Module/InstructionInfoTable.cpp b/lib/Module/InstructionInfoTable.cpp
index e2f05205a633..3d9bf5ae66af 100644
--- a/lib/Module/InstructionInfoTable.cpp
+++ b/lib/Module/InstructionInfoTable.cpp
@@ -94,9 +94,15 @@ bool InstructionInfoTable::getInstructionDebugInfo(const llvm::Instruction *I,
const std::string *&File,
unsigned &Line) {
if (MDNode *N = I->getMetadata("dbg")) {
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+ DILocation *Loc = cast<DILocation>(N);
+ File = internString(getDSPIPath(*Loc));
+ Line = Loc->getLine();
+#else
DILocation Loc(N);
File = internString(getDSPIPath(Loc));
Line = Loc.getLineNumber();
+#endif
return true;
}
diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp
index a86adc98a1b1..b07d3d2fe348 100644
--- a/lib/Module/ModuleUtil.cpp
+++ b/lib/Module/ModuleUtil.cpp
@@ -258,13 +258,21 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
Module *Result = 0;
// FIXME: Maybe load bitcode file lazily? Then if we need to link, materialise the module
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
- ErrorOr<Module *> resultErr = parseBitcodeFile(buff.get(),
- composite->getContext());
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+ ErrorOr<std::unique_ptr<Module> > resultErr =
+#else
+ ErrorOr<Module *> resultErr =
+#endif
+ parseBitcodeFile(buff.get(), composite->getContext());
ec = resultErr.getError();
if (ec)
errorMessage = ec.message();
else
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+ Result = resultErr->release();
+#else
Result = resultErr.get();
+#endif
#else
Result = ParseBitcodeFile(buff.get(), composite->getContext(),
&errorMessage);
@@ -421,7 +429,12 @@ Module *klee::linkWithLibrary(Module *module,
if (magic == sys::fs::file_magic::bitcode) {
Module *Result = 0;
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
- ErrorOr<Module *> ResultErr = parseBitcodeFile(Buffer, Context);
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+ ErrorOr<std::unique_ptr<Module> > ResultErr =
+#else
+ ErrorOr<Module *> ResultErr =
+#endif
+ parseBitcodeFile(Buffer, Context);
if ((ec = ResultErr.getError())) {
ErrorMessage = ec.message();
#else
@@ -432,7 +445,9 @@ Module *klee::linkWithLibrary(Module *module,
ErrorMessage.c_str());
}
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+ Result = ResultErr->release();
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
Result = ResultErr.get();
#endif
@@ -446,7 +461,10 @@ Module *klee::linkWithLibrary(Module *module,
ErrorMessage.c_str());
}
+// unique_ptr owns the Module, we don't have to delete it
+#if LLVM_VERSION_CODE < LLVM_VERSION(3, 7)
delete Result;
+#endif
} else if (magic == sys::fs::file_magic::archive) {
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
@@ -615,7 +633,11 @@ Module *klee::loadModule(LLVMContext &ctx, const std::string &path, std::string
// The module has taken ownership of the MemoryBuffer so release it
// from the std::unique_ptr
buffer->release();
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+ auto module = errorOrModule->release();
+#else
auto module = *errorOrModule;
+#endif
if (auto ec = module->materializeAllPermanently()) {
errorMsg = ec.message();
diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp
index 02ab446a8d63..64e4863f70b3 100644
--- a/lib/Module/Optimize.cpp
+++ b/lib/Module/Optimize.cpp
@@ -154,7 +154,9 @@ void Optimize(Module *M, const std::string &EntryPoint) {
Passes.add(createVerifierPass());
// Add an appropriate DataLayout instance for this module...
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+ // LLVM 3.7+ doesn't have DataLayoutPass anymore.
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
DataLayoutPass *dlpass = new DataLayoutPass();
dlpass->doInitialization(*M);
addPass(Passes, dlpass);
diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp
index 13e4f7d47e58..c597fa2a7b82 100644
--- a/lib/Module/RaiseAsm.cpp
+++ b/lib/Module/RaiseAsm.cpp
@@ -81,7 +81,10 @@ 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, 6)
+#if 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)
TM = NativeTarget->createTargetMachine(HostTriple, "", "", TargetOptions());
TLI = TM->getSubtargetImpl()->getTargetLowering();
#else
diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp
index 9bdf06f600ce..ea24d89c5aaf 100644
--- a/tools/klee/main.cpp
+++ b/tools/klee/main.cpp
@@ -35,6 +35,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/TargetSelect.h"
--
2.15.1