klee/0002-Make-KLEE-compile-against-LLVM-3.7.patch

315 lines
12 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/Core/ExternalDispatcher.cpp | 4 ++++
lib/Module/InstructionInfoTable.cpp | 8 +++++++-
lib/Module/IntrinsicCleaner.cpp | 14 ++++++++++++++
lib/Module/KModule.cpp | 13 ++++++++++++-
lib/Module/ModuleUtil.cpp | 22 +++++++++++++++++++---
lib/Module/Optimize.cpp | 21 +++++++++++++++++++--
lib/Module/RaiseAsm.cpp | 5 ++++-
tools/klee/main.cpp | 6 +++++-
9 files changed, 91 insertions(+), 9 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/Core/ExternalDispatcher.cpp b/lib/Core/ExternalDispatcher.cpp
index 9701d35add85..d49373f84e64 100644
--- a/lib/Core/ExternalDispatcher.cpp
+++ b/lib/Core/ExternalDispatcher.cpp
@@ -257,7 +257,11 @@ Function *ExternalDispatcher::createDispatcher(Function *target, Instruction *in
LLVM_TYPE_Q Type *argTy = (i < FTy->getNumParams() ? FTy->getParamType(i) :
(*ai)->getType());
Instruction *argI64p =
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+ GetElementPtrInst::Create(nullptr, argI64s,
+#else
GetElementPtrInst::Create(argI64s,
+#endif
ConstantInt::get(Type::getInt32Ty(ctx), idx),
"", dBB);
diff --git a/lib/Module/InstructionInfoTable.cpp b/lib/Module/InstructionInfoTable.cpp
index adf054423f13..625c4a297ead 100644
--- a/lib/Module/InstructionInfoTable.cpp
+++ b/lib/Module/InstructionInfoTable.cpp
@@ -87,7 +87,7 @@ static void buildInstructionToLineMap(Module *m,
}
}
-static std::string getDSPIPath(DILocation Loc) {
+static std::string getDSPIPath(const DILocation &Loc) {
std::string dir = Loc.getDirectory();
std::string file = Loc.getFilename();
if (dir.empty() || file[0] == '/') {
@@ -103,9 +103,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/IntrinsicCleaner.cpp b/lib/Module/IntrinsicCleaner.cpp
index 3f7644af3d37..9af6f9f40f21 100644
--- a/lib/Module/IntrinsicCleaner.cpp
+++ b/lib/Module/IntrinsicCleaner.cpp
@@ -110,11 +110,25 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) {
Value *pSrc = CastInst::CreatePointerCast(src, i64p, "vacopy.cast.src", ii);
Value *val = new LoadInst(pSrc, std::string(), ii); new StoreInst(val, pDst, ii);
Value *off = ConstantInt::get(Type::getInt64Ty(ctx), 1);
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+ pDst = GetElementPtrInst::Create(nullptr, pDst, off, std::string(),
+ ii);
+ pSrc = GetElementPtrInst::Create(nullptr, pSrc, off, std::string(),
+ ii);
+#else
pDst = GetElementPtrInst::Create(pDst, off, std::string(), ii);
pSrc = GetElementPtrInst::Create(pSrc, off, std::string(), ii);
+#endif
val = new LoadInst(pSrc, std::string(), ii); new StoreInst(val, pDst, ii);
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+ pDst = GetElementPtrInst::Create(nullptr, pDst, off, std::string(),
+ ii);
+ pSrc = GetElementPtrInst::Create(nullptr, pSrc, off, std::string(),
+ ii);
+#else
pDst = GetElementPtrInst::Create(pDst, off, std::string(), ii);
pSrc = GetElementPtrInst::Create(pSrc, off, std::string(), ii);
+#endif
val = new LoadInst(pSrc, std::string(), ii); new StoreInst(val, pDst, ii);
}
ii->removeFromParent();
diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp
index 45dc34bfec46..4fac18739aba 100644
--- a/lib/Module/KModule.cpp
+++ b/lib/Module/KModule.cpp
@@ -46,8 +46,11 @@
#else
#include "llvm/IR/CallSite.h"
#endif
-
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+#include "llvm/IR/LegacyPassManager.h"
+#else
#include "llvm/PassManager.h"
+#endif
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/raw_os_ostream.h"
@@ -305,7 +308,11 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts,
// invariant transformations that we will end up doing later so that
// optimize is seeing what is as close as possible to the final
// module.
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+ legacy::PassManager pm;
+#else
PassManager pm;
+#endif
pm.add(new RaiseAsmPass());
if (opts.CheckDivZero) pm.add(new DivCheckPass());
if (opts.CheckOvershift) pm.add(new OvershiftCheckPass());
@@ -373,7 +380,11 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts,
// linked in something with intrinsics but any external calls are
// going to be unresolved. We really need to handle the intrinsics
// directly I think?
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+ legacy::PassManager pm3;
+#else
PassManager pm3;
+#endif
pm3.add(createCFGSimplificationPass());
switch(SwitchType) {
case eSwitchTypeInternal: break;
diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp
index c7f1c6d9d4a7..de0130a2632c 100644
--- a/lib/Module/ModuleUtil.cpp
+++ b/lib/Module/ModuleUtil.cpp
@@ -274,13 +274,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);
@@ -439,7 +447,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
@@ -464,7 +477,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)
diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp
index c0f3f34ca8e8..68acd2b17dda 100644
--- a/lib/Module/Optimize.cpp
+++ b/lib/Module/Optimize.cpp
@@ -16,7 +16,11 @@
//===----------------------------------------------------------------------===//
#include "klee/Config/Version.h"
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+#include "llvm/IR/LegacyPassManager.h"
+#else
#include "llvm/PassManager.h"
+#endif
#include "llvm/Analysis/Passes.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Support/CommandLine.h"
@@ -80,7 +84,11 @@ static cl::alias A1("S", cl::desc("Alias for --strip-debug"),
// A utility function that adds a pass to the pass manager but will also add
// a verifier pass after if we're supposed to verify.
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+static inline void addPass(legacy::PassManager &PM, Pass *P) {
+#else
static inline void addPass(PassManager &PM, Pass *P) {
+#endif
// Add the pass to the pass manager...
PM.add(P);
@@ -91,8 +99,11 @@ static inline void addPass(PassManager &PM, Pass *P) {
namespace llvm {
-
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+static void AddStandardCompilePasses(legacy::PassManager &PM) {
+#else
static void AddStandardCompilePasses(PassManager &PM) {
+#endif
PM.add(createVerifierPass()); // Verify that input is correct
#if LLVM_VERSION_CODE < LLVM_VERSION(3, 0)
@@ -166,14 +177,20 @@ static void AddStandardCompilePasses(PassManager &PM) {
void Optimize(Module *M, const std::string &EntryPoint) {
// Instantiate the pass manager to organize the passes.
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+ legacy::PassManager Passes;
+#else
PassManager Passes;
+#endif
// If we're verifying, start off with a verification pass.
if (VerifyEach)
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 5fc54ef17743..29576ad10e9e 100644
--- a/lib/Module/RaiseAsm.cpp
+++ b/lib/Module/RaiseAsm.cpp
@@ -103,7 +103,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();
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 1)
diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp
index 90d54e064dd3..20b1e33a6617 100644
--- a/tools/klee/main.cpp
+++ b/tools/klee/main.cpp
@@ -46,6 +46,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"
#if LLVM_VERSION_CODE < LLVM_VERSION(3, 0)
@@ -1290,8 +1291,11 @@ int main(int argc, char **argv, char **envp) {
// from the std::unique_ptr
Buffer->release();
}
-
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+ mainModule = mainModuleOrError->release();
+#else
mainModule = *mainModuleOrError;
+#endif
if (auto ec = mainModule->materializeAllPermanently()) {
klee_error("error loading program '%s': %s", InputFile.c_str(),
ec.message().c_str());
--
2.12.0