about summary refs log tree commit diff homepage
path: root/lib/Core
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@gmail.com>2017-02-22 16:10:21 +0100
committerJiri Slaby <jirislaby@gmail.com>2017-02-25 11:11:04 +0100
commit4c8fabc7de30e17ef116b8f413f3a973c29cb56c (patch)
tree29e23676c07a95e83c58b5bcb5f8fd4189efaf45 /lib/Core
parent1b67624c3a2fc1ca6f60d0a2b0f675d046dbba76 (diff)
downloadklee-4c8fabc7de30e17ef116b8f413f3a973c29cb56c.tar.gz
llvm: stop using global context
It was marked as deprecated long time ago and finally removed in LLVM
3.9. Remove all uses of getGlobalContext and create our own context.
Propagate it all over the code then.

[v2] use ctx, not C as name

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Diffstat (limited to 'lib/Core')
-rw-r--r--lib/Core/Executor.cpp13
-rw-r--r--lib/Core/Executor.h4
-rw-r--r--lib/Core/ExternalDispatcher.cpp20
-rw-r--r--lib/Core/ExternalDispatcher.h3
4 files changed, 22 insertions, 18 deletions
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 58603e7c..19a5e3f8 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -343,9 +343,10 @@ const char *Executor::TerminateReasonNames[] = {
   [ Unhandled ] = "xxx",
 };
 
-Executor::Executor(const InterpreterOptions &opts, InterpreterHandler *ih)
+Executor::Executor(LLVMContext &ctx, const InterpreterOptions &opts,
+    InterpreterHandler *ih)
     : Interpreter(opts), kmodule(0), interpreterHandler(ih), searcher(0),
-      externalDispatcher(new ExternalDispatcher()), statsTracker(0),
+      externalDispatcher(new ExternalDispatcher(ctx)), statsTracker(0),
       pathWriter(0), symPathWriter(0), specialFunctionHandler(0),
       processTree(0), replayKTest(0), replayPath(0), usingSeeds(0),
       atMemoryLimit(false), inhibitForking(false), haltExecution(false),
@@ -1552,7 +1553,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
 
       if (!isVoidReturn) {
         LLVM_TYPE_Q Type *t = caller->getType();
-        if (t != Type::getVoidTy(getGlobalContext())) {
+        if (t != Type::getVoidTy(i->getContext())) {
           // may need to do coercion due to bitcasts
           Expr::Width from = result->getWidth();
           Expr::Width to = getWidthForLLVMType(t);
@@ -3087,7 +3088,7 @@ void Executor::callExternalFunction(ExecutionState &state,
   }
 
   LLVM_TYPE_Q Type *resultType = target->inst->getType();
-  if (resultType != Type::getVoidTy(getGlobalContext())) {
+  if (resultType != Type::getVoidTy(function->getContext())) {
     ref<Expr> e = ConstantExpr::fromMemory((void*) args, 
                                            getWidthForLLVMType(resultType));
     bindLocal(target, state, e);
@@ -3756,7 +3757,7 @@ Expr::Width Executor::getWidthForLLVMType(LLVM_TYPE_Q llvm::Type *type) const {
 
 ///
 
-Interpreter *Interpreter::create(const InterpreterOptions &opts,
+Interpreter *Interpreter::create(LLVMContext &ctx, const InterpreterOptions &opts,
                                  InterpreterHandler *ih) {
-  return new Executor(opts, ih);
+  return new Executor(ctx, opts, ih);
 }
diff --git a/lib/Core/Executor.h b/lib/Core/Executor.h
index 93d1443e..4970b8a0 100644
--- a/lib/Core/Executor.h
+++ b/lib/Core/Executor.h
@@ -41,6 +41,7 @@ namespace llvm {
   class Function;
   class GlobalValue;
   class Instruction;
+  class LLVMContext;
 #if LLVM_VERSION_CODE <= LLVM_VERSION(3, 1)
   class TargetData;
 #else
@@ -434,7 +435,8 @@ private:
   void doDumpStates();
 
 public:
-  Executor(const InterpreterOptions &opts, InterpreterHandler *ie);
+  Executor(llvm::LLVMContext &ctx, const InterpreterOptions &opts,
+      InterpreterHandler *ie);
   virtual ~Executor();
 
   const InterpreterHandler& getHandler() {
diff --git a/lib/Core/ExternalDispatcher.cpp b/lib/Core/ExternalDispatcher.cpp
index ecc9912e..01c5f935 100644
--- a/lib/Core/ExternalDispatcher.cpp
+++ b/lib/Core/ExternalDispatcher.cpp
@@ -85,8 +85,8 @@ void *ExternalDispatcher::resolveSymbol(const std::string &name) {
   return addr;
 }
 
-ExternalDispatcher::ExternalDispatcher() {
-  dispatchModule = new Module("ExternalDispatcher", getGlobalContext());
+ExternalDispatcher::ExternalDispatcher(LLVMContext &ctx) {
+  dispatchModule = new Module("ExternalDispatcher", ctx);
 
   std::string error;
   executionEngine = ExecutionEngine::createJIT(dispatchModule, &error);
@@ -195,6 +195,7 @@ Function *ExternalDispatcher::createDispatcher(Function *target, Instruction *in
   if (!resolveSymbol(target->getName()))
     return 0;
 
+  LLVMContext &ctx = target->getContext();
   CallSite cs;
   if (inst->getOpcode()==Instruction::Call) {
     cs = CallSite(cast<CallInst>(inst));
@@ -206,20 +207,20 @@ Function *ExternalDispatcher::createDispatcher(Function *target, Instruction *in
 
   std::vector<LLVM_TYPE_Q Type*> nullary;
   
-  Function *dispatcher = Function::Create(FunctionType::get(Type::getVoidTy(getGlobalContext()), 
+  Function *dispatcher = Function::Create(FunctionType::get(Type::getVoidTy(ctx),
 							    nullary, false),
 					  GlobalVariable::ExternalLinkage, 
 					  "",
 					  dispatchModule);
 
 
-  BasicBlock *dBB = BasicBlock::Create(getGlobalContext(), "entry", dispatcher);
+  BasicBlock *dBB = BasicBlock::Create(ctx, "entry", dispatcher);
 
   // Get a Value* for &gTheArgsP, as an i64**.
   Instruction *argI64sp = 
-    new IntToPtrInst(ConstantInt::get(Type::getInt64Ty(getGlobalContext()), 
+    new IntToPtrInst(ConstantInt::get(Type::getInt64Ty(ctx),
                                       (uintptr_t) (void*) &gTheArgsP),
-                     PointerType::getUnqual(PointerType::getUnqual(Type::getInt64Ty(getGlobalContext()))),
+                     PointerType::getUnqual(PointerType::getUnqual(Type::getInt64Ty(ctx))),
                      "argsp", dBB);
   Instruction *argI64s = new LoadInst(argI64sp, "args", dBB); 
   
@@ -238,8 +239,7 @@ Function *ExternalDispatcher::createDispatcher(Function *target, Instruction *in
                                (*ai)->getType());
     Instruction *argI64p = 
       GetElementPtrInst::Create(argI64s, 
-                                ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 
-                                                 idx), 
+                                ConstantInt::get(Type::getInt32Ty(ctx), idx),
                                 "", dBB);
 
     Instruction *argp = new BitCastInst(argI64p, PointerType::getUnqual(argTy),
@@ -260,14 +260,14 @@ Function *ExternalDispatcher::createDispatcher(Function *target, Instruction *in
 #else
   Instruction *result = CallInst::Create(dispatchTarget, args, args+i, "", dBB);
 #endif
-  if (result->getType() != Type::getVoidTy(getGlobalContext())) {
+  if (result->getType() != Type::getVoidTy(ctx)) {
     Instruction *resp = 
       new BitCastInst(argI64s, PointerType::getUnqual(result->getType()), 
                       "", dBB);
     new StoreInst(result, resp, dBB);
   }
 
-  ReturnInst::Create(getGlobalContext(), dBB);
+  ReturnInst::Create(ctx, dBB);
 
   delete[] args;
 
diff --git a/lib/Core/ExternalDispatcher.h b/lib/Core/ExternalDispatcher.h
index d8d9dc58..94363bab 100644
--- a/lib/Core/ExternalDispatcher.h
+++ b/lib/Core/ExternalDispatcher.h
@@ -17,6 +17,7 @@
 namespace llvm {
   class ExecutionEngine;
   class Instruction;
+  class LLVMContext;
   class Function;
   class FunctionType;
   class Module;
@@ -35,7 +36,7 @@ namespace klee {
     bool runProtectedCall(llvm::Function *f, uint64_t *args);
     
   public:
-    ExternalDispatcher();
+    ExternalDispatcher(llvm::LLVMContext &ctx);
     ~ExternalDispatcher();
 
     /* Call the given function using the parameter passing convention of