about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorFrank Busse <bb0xfb@gmail.com>2021-12-15 16:20:29 +0000
committerCristian Cadar <c.cadar@imperial.ac.uk>2022-03-17 22:59:26 +0000
commitd8553f3cec042b5af9e21c268cb14ee8f7b30083 (patch)
treed8545f09d6ae508df5a8d19ad30b6dbd6f1e4182
parent8cab09eb98d06d488e036ceec9f4b16090502297 (diff)
downloadklee-d8553f3cec042b5af9e21c268cb14ee8f7b30083.tar.gz
remove LLVM < 6 from sources
-rw-r--r--include/klee/Config/Version.h14
-rw-r--r--include/klee/Support/PrintVersion.h4
-rw-r--r--lib/Core/Executor.cpp55
-rw-r--r--lib/Core/ExecutorUtil.cpp4
-rw-r--r--lib/Core/GetElementPtrTypeIterator.h2
-rw-r--r--lib/Core/MemoryManager.cpp5
-rw-r--r--lib/Expr/AssignmentGenerator.cpp4
-rw-r--r--lib/Expr/Expr.cpp12
-rw-r--r--lib/Module/FunctionAlias.cpp23
-rw-r--r--lib/Module/InstructionInfoTable.cpp5
-rw-r--r--lib/Module/IntrinsicCleaner.cpp23
-rw-r--r--lib/Module/KModule.cpp4
-rw-r--r--lib/Module/ModuleUtil.cpp56
-rw-r--r--lib/Module/Optimize.cpp25
-rw-r--r--lib/Module/RaiseAsm.cpp21
-rw-r--r--lib/Support/PrintVersion.cpp11
-rw-r--r--tools/kleaver/main.cpp4
-rw-r--r--tools/klee/main.cpp10
18 files changed, 16 insertions, 266 deletions
diff --git a/include/klee/Config/Version.h b/include/klee/Config/Version.h
index 0e7b75e3..f3ef8fa5 100644
--- a/include/klee/Config/Version.h
+++ b/include/klee/Config/Version.h
@@ -14,17 +14,7 @@
 
 #define LLVM_VERSION(major, minor) (((major) << 8) | (minor))
 #define LLVM_VERSION_CODE LLVM_VERSION(LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR)
-
-#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
-#  define KLEE_LLVM_CL_VAL_END
-#else
-#  define KLEE_LLVM_CL_VAL_END , clEnumValEnd
-#endif
-
-#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
-#  define KLEE_LLVM_GOIF_TERMINATOR
-#else
-#  define KLEE_LLVM_GOIF_TERMINATOR , NULL
-#endif
+#define KLEE_LLVM_CL_VAL_END
+#define KLEE_LLVM_GOIF_TERMINATOR
 
 #endif /* KLEE_VERSION_H */
diff --git a/include/klee/Support/PrintVersion.h b/include/klee/Support/PrintVersion.h
index fbd20e39..1c952451 100644
--- a/include/klee/Support/PrintVersion.h
+++ b/include/klee/Support/PrintVersion.h
@@ -15,11 +15,7 @@
 #include "klee/Config/Version.h"
 
 namespace klee {
-#if LLVM_VERSION_CODE >= LLVM_VERSION(6, 0)
   void printVersion(llvm::raw_ostream &OS);
-#else
-  void printVersion();
-#endif
 }
 
 #endif /* KLEE_PRINTVERSION_H */
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 85413a42..1f1fb18c 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -1422,21 +1422,12 @@ void Executor::stepInstruction(ExecutionState &state) {
 
 static inline const llvm::fltSemantics *fpWidthToSemantics(unsigned width) {
   switch (width) {
-#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
   case Expr::Int32:
     return &llvm::APFloat::IEEEsingle();
   case Expr::Int64:
     return &llvm::APFloat::IEEEdouble();
   case Expr::Fl80:
     return &llvm::APFloat::x87DoubleExtended();
-#else
-  case Expr::Int32:
-    return &llvm::APFloat::IEEEsingle;
-  case Expr::Int64:
-    return &llvm::APFloat::IEEEdouble;
-  case Expr::Fl80:
-    return &llvm::APFloat::x87DoubleExtended;
-#endif
   default:
     return 0;
   }
@@ -1936,19 +1927,8 @@ void Executor::executeCall(ExecutionState &state, KInstruction *ki, Function *f,
 #if LLVM_VERSION_CODE >= LLVM_VERSION(11, 0)
           MaybeAlign ma = cs.getParamAlign(k);
           unsigned alignment = ma ? ma->value() : 0;
-#elif LLVM_VERSION_CODE > LLVM_VERSION(4, 0)
-          unsigned alignment = cs.getParamAlignment(k);
 #else
-          // getParamAlignment() is buggy for LLVM <= 4, so we instead
-          // get the attribute in a hacky way by parsing the textual
-          // representation
-          unsigned alignment = 0;
-          std::string str;
-          llvm::raw_string_ostream s(str);
-          s << *cs.getArgument(k);
-          size_t pos = str.find("align ");
-          if (pos != std::string::npos)
-            alignment = std::stoi(str.substr(pos + 6));
+          unsigned alignment = cs.getParamAlignment(k);
 #endif
 
           // AMD64-ABI 3.5.7p5: Step 7. Align l->overflow_arg_area upwards to a
@@ -1962,21 +1942,13 @@ void Executor::executeCall(ExecutionState &state, KInstruction *ki, Function *f,
           if (!alignment)
             alignment = 8;
 
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
           size = llvm::alignTo(size, alignment);
-#else
-          size = llvm::RoundUpToAlignment(size, alignment);
-#endif
           offsets[k] = size;
 
           // AMD64-ABI 3.5.7p5: Step 9. Set l->overflow_arg_area to:
           // l->overflow_arg_area + sizeof(type)
           // Step 10. Align l->overflow_arg_area upwards to an 8 byte boundary.
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
           size += llvm::alignTo(argWidth, WordSize) / 8;
-#else
-          size += llvm::RoundUpToAlignment(argWidth, WordSize) / 8;
-#endif
         }
       }
 
@@ -2161,11 +2133,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
 #endif
 
             // XXX need to check other param attrs ?
-#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
             bool isSExt = cs.hasRetAttr(llvm::Attribute::SExt);
-#else
-            bool isSExt = cs.paramHasAttr(0, llvm::Attribute::SExt);
-#endif
             if (isSExt) {
               result = SExtExpr::create(result, to);
             } else {
@@ -2299,11 +2267,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
       // switch to an internal rep.
       llvm::IntegerType *Ty = cast<IntegerType>(si->getCondition()->getType());
       ConstantInt *ci = ConstantInt::get(Ty, CE->getZExtValue());
-#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
       unsigned index = si->findCaseValue(ci)->getSuccessorIndex();
-#else
-      unsigned index = si->findCaseValue(ci).getSuccessorIndex();
-#endif
       transferToBasicBlock(si->getSuccessor(index), si->getParent(), state);
     } else {
       // Handle possible different branch targets
@@ -2470,11 +2434,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
 
             if (from != to) {
               // XXX need to check other param attrs ?
-#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
               bool isSExt = cs.paramHasAttr(i, llvm::Attribute::SExt);
-#else
-              bool isSExt = cs.paramHasAttr(i+1, llvm::Attribute::SExt);
-#endif
               if (isSExt) {
                 arguments[i] = SExtExpr::create(arguments[i], to);
               } else {
@@ -2975,11 +2935,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
     llvm::APFloat Arg(*fpWidthToSemantics(arg->getWidth()), arg->getAPValue());
     uint64_t value = 0;
     bool isExact = true;
-#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
     auto valueRef = makeMutableArrayRef(value);
-#else
-    uint64_t *valueRef = &value;
-#endif
     Arg.convertToInteger(valueRef, resultType, false,
                          llvm::APFloat::rmTowardZero, &isExact);
     bindLocal(ki, state, ConstantExpr::alloc(value, resultType));
@@ -2997,11 +2953,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
 
     uint64_t value = 0;
     bool isExact = true;
-#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
     auto valueRef = makeMutableArrayRef(value);
-#else
-    uint64_t *valueRef = &value;
-#endif
     Arg.convertToInteger(valueRef, resultType, true,
                          llvm::APFloat::rmTowardZero, &isExact);
     bindLocal(ki, state, ConstantExpr::alloc(value, resultType));
@@ -3397,17 +3349,12 @@ void Executor::computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie) {
       uint64_t addend = sl->getElementOffset((unsigned) ci->getZExtValue());
       constantOffset = constantOffset->Add(ConstantExpr::alloc(addend,
                                                                Context::get().getPointerWidth()));
-#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
     } else if (isa<ArrayType>(*ii)) {
       computeOffsetsSeqTy<ArrayType>(kgepi, constantOffset, index, ii);
     } else if (isa<VectorType>(*ii)) {
       computeOffsetsSeqTy<VectorType>(kgepi, constantOffset, index, ii);
     } else if (isa<PointerType>(*ii)) {
       computeOffsetsSeqTy<PointerType>(kgepi, constantOffset, index, ii);
-#else
-    } else if (isa<SequentialType>(*ii)) {
-      computeOffsetsSeqTy<SequentialType>(kgepi, constantOffset, index, ii);
-#endif
     } else
       assert("invalid type" && 0);
     index++;
diff --git a/lib/Core/ExecutorUtil.cpp b/lib/Core/ExecutorUtil.cpp
index 84226a64..1050ba23 100644
--- a/lib/Core/ExecutorUtil.cpp
+++ b/lib/Core/ExecutorUtil.cpp
@@ -214,11 +214,7 @@ namespace klee {
           continue;
 
         // Handle a struct index, which adds its field offset to the pointer.
-#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
         if (auto STy = ii.getStructTypeOrNull()) {
-#else
-        if (StructType *STy = dyn_cast<StructType>(*ii)) {
-#endif
           unsigned ElementIdx = indexOp->getZExtValue();
           const StructLayout *SL = kmodule->targetData->getStructLayout(STy);
           base = base->Add(
diff --git a/lib/Core/GetElementPtrTypeIterator.h b/lib/Core/GetElementPtrTypeIterator.h
index 87de667d..89606a0a 100644
--- a/lib/Core/GetElementPtrTypeIterator.h
+++ b/lib/Core/GetElementPtrTypeIterator.h
@@ -88,10 +88,8 @@ class generic_gep_type_iterator
       if (llvm::CompositeType *CT = dyn_cast<llvm::CompositeType>(CurTy)) {
         CurTy = CT->getTypeAtIndex(getOperand());
 #endif
-#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
       } else if (auto ptr = dyn_cast<llvm::PointerType>(CurTy)) {
         CurTy = ptr->getElementType();
-#endif
       } else {
         CurTy = 0;
       }
diff --git a/lib/Core/MemoryManager.cpp b/lib/Core/MemoryManager.cpp
index e3fffd9b..f15c0db9 100644
--- a/lib/Core/MemoryManager.cpp
+++ b/lib/Core/MemoryManager.cpp
@@ -116,12 +116,7 @@ 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/Expr/AssignmentGenerator.cpp b/lib/Expr/AssignmentGenerator.cpp
index be77765e..5ec7c511 100644
--- a/lib/Expr/AssignmentGenerator.cpp
+++ b/lib/Expr/AssignmentGenerator.cpp
@@ -332,11 +332,7 @@ AssignmentGenerator::getIndexedValue(const std::vector<unsigned char> &c_val,
                                      const unsigned int size) {
   std::vector<unsigned char> toReturn;
   const llvm::APInt index_val = index.getAPValue();
-#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
   assert(!index_val.isSignMask() && "Negative index");
-#else
-  assert(!index_val.isSignBit() && "Negative index");
-#endif
   const uint64_t id = index_val.getZExtValue() / c_val.size();
   uint64_t arraySize = size / c_val.size();
   for (uint64_t i = 0; i < arraySize; ++i) {
diff --git a/lib/Expr/Expr.cpp b/lib/Expr/Expr.cpp
index 2b9eab0d..50020fb1 100644
--- a/lib/Expr/Expr.cpp
+++ b/lib/Expr/Expr.cpp
@@ -343,13 +343,11 @@ ref<Expr> ConstantExpr::fromMemory(void *address, Width width) {
   case Expr::Int64: return ConstantExpr::create(*((uint64_t*) address), width);
   // FIXME: what about machines without x87 support?
   default:
-    return ConstantExpr::alloc(llvm::APInt(width,
-#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
-      (width+llvm::APFloatBase::integerPartWidth-1)/llvm::APFloatBase::integerPartWidth,
-#else
-      (width+llvm::integerPartWidth-1)/llvm::integerPartWidth,
-#endif
-      (const uint64_t*)address));
+    return ConstantExpr::alloc(
+        llvm::APInt(width,
+                    (width + llvm::APFloatBase::integerPartWidth - 1) /
+                        llvm::APFloatBase::integerPartWidth,
+                    (const uint64_t *)address));
   }
 }
 
diff --git a/lib/Module/FunctionAlias.cpp b/lib/Module/FunctionAlias.cpp
index 3fb0ec9a..a98b74fb 100644
--- a/lib/Module/FunctionAlias.cpp
+++ b/lib/Module/FunctionAlias.cpp
@@ -36,9 +36,7 @@ namespace klee {
 bool FunctionAliasPass::runOnModule(Module &M) {
   bool modified = false;
 
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
   assert((M.ifunc_size() == 0) && "Unexpected ifunc");
-#endif
 
   for (const auto &pair : FunctionAlias) {
     bool matchFound = false;
@@ -93,28 +91,7 @@ bool FunctionAliasPass::runOnModule(Module &M) {
     std::vector<GlobalValue *> matches;
 
     // find matches for regex
-#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
     for (GlobalValue &global : M.global_values()) {
-#else
-    // chain iterators of alias list and function list
-    auto firstIt = M.getAliasList().begin();
-    auto firstIe = M.getAliasList().end();
-    auto secondIt = M.getFunctionList().begin();
-    auto secondIe = M.getFunctionList().end();
-    for (bool firstList = true;;
-         (firstList && (++firstIt != firstIe)) || (++secondIt != secondIe)) {
-      GlobalValue *gv = nullptr;
-      if (firstIt == firstIe)
-        firstList = false;
-      if (firstList) {
-        gv = cast<GlobalValue>(&*firstIt);
-      } else {
-        if (secondIt == secondIe)
-          break;
-        gv = cast<GlobalValue>(&*secondIt);
-      }
-      GlobalValue &global = *gv;
-#endif
       if (!global.hasName())
         continue;
 
diff --git a/lib/Module/InstructionInfoTable.cpp b/lib/Module/InstructionInfoTable.cpp
index 05a1f7b9..3c972edc 100644
--- a/lib/Module/InstructionInfoTable.cpp
+++ b/lib/Module/InstructionInfoTable.cpp
@@ -112,11 +112,8 @@ public:
 
   std::unique_ptr<FunctionInfo> getFunctionInfo(const llvm::Function &Func) {
     auto asmLine = lineTable.at(reinterpret_cast<std::uintptr_t>(&Func));
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
     auto dsub = Func.getSubprogram();
-#else
-    auto dsub = llvm::getDISubprogram(&Func);
-#endif
+
     if (dsub != nullptr) {
       auto path = dsub->getFilename();
       return std::make_unique<FunctionInfo>(FunctionInfo(
diff --git a/lib/Module/IntrinsicCleaner.cpp b/lib/Module/IntrinsicCleaner.cpp
index f4b867e5..d15db10a 100644
--- a/lib/Module/IntrinsicCleaner.cpp
+++ b/lib/Module/IntrinsicCleaner.cpp
@@ -317,30 +317,9 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) {
         break;
       }
       case Intrinsic::objectsize: {
-#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
         // Lower the call to a concrete value
         auto replacement = llvm::lowerObjectSizeCall(ii, DataLayout, nullptr,
                                                      /*MustSucceed=*/true);
-#else
-        // We don't know the size of an object in general so we replace
-        // with 0 or -1 depending on the second argument to the intrinsic.
-        assert(ii->getNumArgOperands() == 2 && "wrong number of arguments");
-        auto minArg = dyn_cast_or_null<ConstantInt>(ii->getArgOperand(1));
-        assert(minArg &&
-               "Failed to get second argument or it is not ConstantInt");
-        assert(minArg->getBitWidth() == 1 && "Second argument is not an i1");
-        ConstantInt *replacement = nullptr;
-        IntegerType *intType = dyn_cast<IntegerType>(ii->getType());
-        assert(intType && "intrinsic does not have integer return type");
-        if (minArg->isZero()) {
-          // min=false
-          replacement = ConstantInt::get(intType, -1, /*isSigned=*/true);
-        } else {
-          // min=true
-          replacement = ConstantInt::get(intType, 0, /*isSigned=*/false);
-        }
-
-#endif
         ii->replaceAllUsesWith(replacement);
         ii->eraseFromParent();
         dirty = true;
@@ -361,9 +340,7 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) {
       // The following intrinsics are currently handled by LowerIntrinsicCall
       // (Invoking LowerIntrinsicCall with any intrinsics not on this
       // list throws an exception.)
-#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
       case Intrinsic::addressofreturnaddress:
-#endif
       case Intrinsic::annotation:
       case Intrinsic::assume:
       case Intrinsic::bswap:
diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp
index 50bb28bb..2f78ce14 100644
--- a/lib/Module/KModule.cpp
+++ b/lib/Module/KModule.cpp
@@ -22,11 +22,7 @@
 #include "klee/Support/ErrorHandling.h"
 #include "klee/Support/ModuleUtil.h"
 
-#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
 #include "llvm/Bitcode/BitcodeWriter.h"
-#else
-#include "llvm/Bitcode/ReaderWriter.h"
-#endif
 #if LLVM_VERSION_CODE < LLVM_VERSION(8, 0)
 #include "llvm/IR/CallSite.h"
 #endif
diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp
index 2c855261..87a9c917 100644
--- a/lib/Module/ModuleUtil.cpp
+++ b/lib/Module/ModuleUtil.cpp
@@ -14,9 +14,8 @@
 #include "klee/Support/ErrorHandling.h"
 
 #include "llvm/Analysis/ValueTracking.h"
-#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
 #include "llvm/BinaryFormat/Magic.h"
-#endif
+#include "llvm/Bitcode/BitcodeReader.h"
 #include "llvm/IR/AssemblyAnnotationWriter.h"
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/DiagnosticPrinter.h"
@@ -31,20 +30,12 @@
 #include "llvm/Object/Archive.h"
 #include "llvm/Object/Error.h"
 #include "llvm/Object/ObjectFile.h"
-#if LLVM_VERSION_CODE < LLVM_VERSION(4, 0)
-#include "llvm/Support/DataStream.h"
-#endif
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/SourceMgr.h"
 
-#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
-#include <llvm/Bitcode/BitcodeReader.h>
-#else
-#include <llvm/Bitcode/ReaderWriter.h>
-#endif
 
 #include <algorithm>
 #include <fstream>
@@ -304,11 +295,7 @@ Function *klee::getDirectCallTarget(
     } else 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 = nullptr;
@@ -383,18 +370,9 @@ bool klee::loadFile(const std::string &fileName, LLVMContext &context,
   }
 
   MemoryBufferRef Buffer = bufferErr.get()->getMemBufferRef();
-
-#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
   file_magic magic = identify_magic(Buffer.getBuffer());
-#else
-  sys::fs::file_magic magic = sys::fs::identify_magic(Buffer.getBuffer());
-#endif
 
-#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
   if (magic == file_magic::bitcode) {
-#else
-  if (magic == sys::fs::file_magic::bitcode) {
-#endif
     SMDiagnostic Err;
     std::unique_ptr<llvm::Module> module(parseIR(Buffer, Err, context));
     if (!module) {
@@ -405,37 +383,21 @@ bool klee::loadFile(const std::string &fileName, LLVMContext &context,
     return true;
   }
 
-#if LLVM_VERSION_CODE >= LLVM_VERSION(5, 0)
   if (magic == file_magic::archive) {
-#else
-  if (magic == sys::fs::file_magic::archive) {
-#endif
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
     Expected<std::unique_ptr<object::Binary> > archOwner =
       object::createBinary(Buffer, &context);
     if (!archOwner)
       ec = errorToErrorCode(archOwner.takeError());
     llvm::object::Binary *arch = archOwner.get().get();
-#else
-    ErrorOr<std::unique_ptr<object::Binary>> archOwner =
-        object::createBinary(Buffer, &context);
-    ec = archOwner.getError();
-    llvm::object::Binary *arch = archOwner.get().get();
-#endif
     if (ec)
       klee_error("Loading file %s failed: %s", fileName.c_str(),
                  ec.message().c_str());
 
     if (auto archive = dyn_cast<object::Archive>(arch)) {
 // Load all bitcode files into memory
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
       auto Err = Error::success();
       for (auto AI = archive->child_begin(Err), AE = archive->child_end();
            AI != AE; ++AI)
-#else
-      for (auto AI = archive->child_begin(), AE = archive->child_end();
-           AI != AE; ++AI)
-#endif
       {
 
         StringRef memberName;
@@ -447,12 +409,8 @@ bool klee::loadFile(const std::string &fileName, LLVMContext &context,
                 return false;
         }
         auto memberNameErr = childOrErr->getName();
-#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
         ec = memberNameErr ? std::error_code() :
                 errorToErrorCode(memberNameErr.takeError());
-#else
-        ec = memberNameErr.getError();
-#endif
         if (!ec) {
           memberName = memberNameErr.get();
           KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs()
@@ -463,24 +421,14 @@ bool klee::loadFile(const std::string &fileName, LLVMContext &context,
           return false;
         }
 
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
         Expected<std::unique_ptr<llvm::object::Binary> > child =
             childOrErr->getAsBinary();
         if (!child)
           ec = errorToErrorCode(child.takeError());
-#else
-        ErrorOr<std::unique_ptr<llvm::object::Binary>> child =
-            childOrErr->getAsBinary();
-        ec = child.getError();
-#endif
         if (ec) {
 // If we can't open as a binary object file its hopefully a bitcode file
           auto buff = childOrErr->getMemoryBufferRef();
-#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
           ec = buff ? std::error_code() : errorToErrorCode(buff.takeError());
-#else
-          ec = buff.getError();
-#endif
           if (ec) {
             errorMsg = "Failed to get MemoryBuffer: " + ec.message();
             return false;
@@ -513,12 +461,10 @@ bool klee::loadFile(const std::string &fileName, LLVMContext &context,
           return false;
         }
       }
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
       if (Err) {
         errorMsg = "Cannot iterate over archive";
         return false;
       }
-#endif
     }
 
     return true;
diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp
index 153c9bb8..a58d2459 100644
--- a/lib/Module/Optimize.cpp
+++ b/lib/Module/Optimize.cpp
@@ -34,12 +34,9 @@
 #include "llvm/Support/PluginLoader.h"
 #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/IPO/FunctionAttrs.h"
+#include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Scalar/GVN.h"
-#endif
 
 #if LLVM_VERSION_CODE >= LLVM_VERSION(7, 0)
 #include "llvm/Transforms/Utils.h"
@@ -118,11 +115,7 @@ static void AddStandardCompilePasses(legacy::PassManager &PM) {
   addPass(PM, createCFGSimplificationPass());    // Clean up after IPCP & DAE
 
   addPass(PM, createPruneEHPass());              // Remove dead EH info
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
   addPass(PM, createPostOrderFunctionAttrsLegacyPass());
-#else
-  addPass(PM, createPostOrderFunctionAttrsPass());
-#endif
   addPass(PM, createReversePostOrderFunctionAttrsPass()); // Deduce function attrs
 
   if (!DisableInline)
@@ -132,11 +125,7 @@ static void AddStandardCompilePasses(legacy::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
@@ -189,7 +178,6 @@ void Optimize(Module *M, llvm::ArrayRef<const char *> preservedFunctions) {
   // for a main function.  If main is defined, mark all other functions
   // internal.
   if (!DisableInternalize) {
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
     auto PreserveFunctions = [=](const GlobalValue &GV) {
       StringRef GVName = GV.getName();
 
@@ -200,9 +188,6 @@ void Optimize(Module *M, llvm::ArrayRef<const char *> preservedFunctions) {
       return false;
     };
     ModulePass *pass = createInternalizePass(PreserveFunctions);
-#else
-    ModulePass *pass = createInternalizePass(preservedFunctions);
-#endif
     addPass(Passes, pass);
   }
 
@@ -241,18 +226,10 @@ void Optimize(Module *M, llvm::ArrayRef<const char *> preservedFunctions) {
   // 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, 9)
   addPass(Passes, createPostOrderFunctionAttrsLegacyPass());
-#else
-  addPass(Passes, createPostOrderFunctionAttrsPass());
-#endif
   addPass(Passes, createReversePostOrderFunctionAttrsPass()); // Add nocapture
   addPass(Passes, createGlobalsAAWrapperPass()); // IP alias analysis
 
diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp
index 55550864..248b4344 100644
--- a/lib/Module/RaiseAsm.cpp
+++ b/lib/Module/RaiseAsm.cpp
@@ -11,6 +11,8 @@
 #include "klee/Config/Version.h"
 #include "klee/Support/ErrorHandling.h"
 
+#include "llvm/CodeGen/TargetLowering.h"
+#include "llvm/CodeGen/TargetSubtargetInfo.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/InlineAsm.h"
@@ -18,16 +20,8 @@
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/TargetRegistry.h"
-#include "llvm/Support/raw_ostream.h"
-#if LLVM_VERSION_CODE >= LLVM_VERSION(6, 0)
-#include "llvm/CodeGen/TargetLowering.h"
-#include "llvm/CodeGen/TargetSubtargetInfo.h"
 #include "llvm/Target/TargetMachine.h"
-#else
-#include "llvm/Target/TargetLowering.h"
-#include "llvm/Target/TargetMachine.h"
-#include "llvm/Target/TargetSubtargetInfo.h"
-#endif
+
 
 using namespace llvm;
 using namespace klee;
@@ -70,11 +64,7 @@ bool RaiseAsmPass::runOnInstruction(Module &M, Instruction *I) {
     if (ia->getAsmString() == "" && ia->hasSideEffects() &&
         ia->getFunctionType()->getReturnType()->isVoidTy()) {
       IRBuilder<> Builder(I);
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
       Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent);
-#else
-      Builder.CreateFence(llvm::SequentiallyConsistent);
-#endif
       I->eraseFromParent();
       return true;
     }
@@ -98,14 +88,9 @@ bool RaiseAsmPass::runOnModule(Module &M) {
     klee_warning("Warning: unable to select target: %s", Err.c_str());
     TLI = 0;
   } else {
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
     TM = Target->createTargetMachine(TargetTriple, "", "", TargetOptions(),
                                      None);
     TLI = TM->getSubtargetImpl(*(M.begin()))->getTargetLowering();
-#else
-    TM = Target->createTargetMachine(TargetTriple, "", "", TargetOptions());
-    TLI = TM->getSubtargetImpl(*(M.begin()))->getTargetLowering();
-#endif
 
     triple = llvm::Triple(TargetTriple);
   }
diff --git a/lib/Support/PrintVersion.cpp b/lib/Support/PrintVersion.cpp
index 1cb80864..29235f53 100644
--- a/lib/Support/PrintVersion.cpp
+++ b/lib/Support/PrintVersion.cpp
@@ -15,16 +15,7 @@
 
 #include "klee/Config/CompileTimeInfo.h"
 
-#if LLVM_VERSION_CODE >= LLVM_VERSION(6, 0)
-void klee::printVersion(llvm::raw_ostream &OS)
-#else
-void klee::printVersion()
-#endif
-{
-#if LLVM_VERSION_CODE < LLVM_VERSION(6, 0)
-  llvm::raw_ostream &OS = llvm::outs();
-#endif
-
+void klee::printVersion(llvm::raw_ostream &OS) {
   OS << PACKAGE_STRING " (" PACKAGE_URL ")\n";
 #ifdef KLEE_ENABLE_TIMESTAMP
   OS << "  Built " __DATE__ " (" __TIME__ ")\n";
diff --git a/tools/kleaver/main.cpp b/tools/kleaver/main.cpp
index 0a4cfbff..558e7daf 100644
--- a/tools/kleaver/main.cpp
+++ b/tools/kleaver/main.cpp
@@ -395,11 +395,7 @@ 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 f68e3b27..740b33d7 100644
--- a/tools/klee/main.cpp
+++ b/tools/klee/main.cpp
@@ -24,6 +24,7 @@
 #include "klee/Support/PrintVersion.h"
 #include "klee/System/Time.h"
 
+#include "llvm/Bitcode/BitcodeReader.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/InstrTypes.h"
@@ -43,11 +44,6 @@
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/Signals.h"
 
-#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
-#include <llvm/Bitcode/BitcodeReader.h>
-#else
-#include <llvm/Bitcode/ReaderWriter.h>
-#endif
 
 #include <dirent.h>
 #include <signal.h>
@@ -1167,11 +1163,7 @@ 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.empty()) {