diff options
author | Julian Büning <julian.buening@rwth-aachen.de> | 2019-07-17 22:42:12 +0200 |
---|---|---|
committer | MartinNowack <martin.nowack@gmail.com> | 2019-10-31 15:35:05 +0000 |
commit | e32ae5ae50165593b82cffb6e946532618000933 (patch) | |
tree | b7ad0b2122e21c92a73ea68aeaab51a3937e2a88 | |
parent | 2b78a26d9dbeb7823c5a3487bfa2535fb4b274bf (diff) | |
download | klee-e32ae5ae50165593b82cffb6e946532618000933.tar.gz |
support compilation against LLVM 9.0
-rw-r--r-- | lib/Module/Checks.cpp | 8 | ||||
-rw-r--r-- | lib/Module/IntrinsicCleaner.cpp | 17 | ||||
-rw-r--r-- | lib/Module/KModule.cpp | 9 | ||||
-rw-r--r-- | lib/Solver/SolverCmdLine.cpp | 21 | ||||
-rw-r--r-- | tools/klee/main.cpp | 18 |
5 files changed, 43 insertions, 30 deletions
diff --git a/lib/Module/Checks.cpp b/lib/Module/Checks.cpp index 10481f14..7bb8ec50 100644 --- a/lib/Module/Checks.cpp +++ b/lib/Module/Checks.cpp @@ -71,9 +71,9 @@ bool DivCheckPass::runOnModule(Module &M) { LLVMContext &ctx = M.getContext(); KleeIRMetaData md(ctx); - auto divZeroCheckFunction = cast<Function>( + auto divZeroCheckFunction = M.getOrInsertFunction("klee_div_zero_check", Type::getVoidTy(ctx), - Type::getInt64Ty(ctx) KLEE_LLVM_GOIF_TERMINATOR)); + Type::getInt64Ty(ctx) KLEE_LLVM_GOIF_TERMINATOR); for (auto &divInst : divInstruction) { llvm::IRBuilder<> Builder(divInst /* Inserts before divInst*/); @@ -130,9 +130,9 @@ bool OvershiftCheckPass::runOnModule(Module &M) { // Retrieve the checker function auto &ctx = M.getContext(); KleeIRMetaData md(ctx); - auto overshiftCheckFunction = cast<Function>(M.getOrInsertFunction( + auto overshiftCheckFunction = M.getOrInsertFunction( "klee_overshift_check", Type::getVoidTy(ctx), Type::getInt64Ty(ctx), - Type::getInt64Ty(ctx) KLEE_LLVM_GOIF_TERMINATOR)); + Type::getInt64Ty(ctx) KLEE_LLVM_GOIF_TERMINATOR); for (auto &shiftInst : shiftInstructions) { llvm::IRBuilder<> Builder(shiftInst); diff --git a/lib/Module/IntrinsicCleaner.cpp b/lib/Module/IntrinsicCleaner.cpp index 921e6766..1c30d781 100644 --- a/lib/Module/IntrinsicCleaner.cpp +++ b/lib/Module/IntrinsicCleaner.cpp @@ -264,14 +264,19 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) { case Intrinsic::trap: { // Intrinsic instruction "llvm.trap" found. Directly lower it to // a call of the abort() function. - Function *F = cast<Function>( - M.getOrInsertFunction("abort", Type::getVoidTy(ctx) - KLEE_LLVM_GOIF_TERMINATOR)); - F->setDoesNotReturn(); - F->setDoesNotThrow(); + auto C = M.getOrInsertFunction("abort", Type::getVoidTy(ctx) + KLEE_LLVM_GOIF_TERMINATOR); +#if LLVM_VERSION_CODE >= LLVM_VERSION(9, 0) + if (auto *F = dyn_cast<Function>(C.getCallee())) { +#else + if (auto *F = dyn_cast<Function>(C)) { +#endif + F->setDoesNotReturn(); + F->setDoesNotThrow(); + } llvm::IRBuilder<> Builder(ii); - Builder.CreateCall(F); + Builder.CreateCall(C); Builder.CreateUnreachable(); i = ii->eraseFromParent(); diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp index 315942b5..cec0ea6f 100644 --- a/lib/Module/KModule.cpp +++ b/lib/Module/KModule.cpp @@ -140,10 +140,15 @@ static Function *getStubFunctionForCtorList(Module *m, if (arr) { for (unsigned i=0; i<arr->getNumOperands(); i++) { auto cs = cast<ConstantStruct>(arr->getOperand(i)); - // There is a third *optional* element in global_ctor elements (``i8 - // @data``). + // There is a third element in global_ctor elements (``i8 @data``). +#if LLVM_VERSION_CODE >= LLVM_VERSION(9, 0) + assert(cs->getNumOperands() == 3 && + "unexpected element in ctor initializer list"); +#else + // before LLVM 9.0, the third operand was optional assert((cs->getNumOperands() == 2 || cs->getNumOperands() == 3) && "unexpected element in ctor initializer list"); +#endif auto fp = cs->getOperand(1); if (!fp->isNullValue()) { if (auto ce = dyn_cast<llvm::ConstantExpr>(fp)) diff --git a/lib/Solver/SolverCmdLine.cpp b/lib/Solver/SolverCmdLine.cpp index 87b66317..6cc13b17 100644 --- a/lib/Solver/SolverCmdLine.cpp +++ b/lib/Solver/SolverCmdLine.cpp @@ -118,18 +118,15 @@ void KCommandLine::HideOptions(llvm::cl::OptionCategory &Category) { StringMap<cl::Option *> &map = cl::getRegisteredOptions(); for (auto &elem : map) { - if (elem.second->Category == &Category) { - elem.second->setHiddenFlag(cl::Hidden); - } - } -} - -void KCommandLine::HideUnrelatedOptions(cl::OptionCategory &Category) { - StringMap<cl::Option *> &map = cl::getRegisteredOptions(); - for (StringMap<cl::Option *>::iterator i = map.begin(), e = map.end(); i != e; - i++) { - if (i->second->Category != &Category) { - i->second->setHiddenFlag(cl::Hidden); +#if LLVM_VERSION_CODE >= LLVM_VERSION(9, 0) + for (auto &cat : elem.second->Categories) { +#else + { + auto &cat = elem.second->Category; +#endif + if (cat == &Category) { + elem.second->setHiddenFlag(cl::Hidden); + } } } } diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp index de2989f6..51ce9530 100644 --- a/tools/klee/main.cpp +++ b/tools/klee/main.cpp @@ -715,9 +715,10 @@ preparePOSIX(std::vector<std::unique_ptr<llvm::Module>> &loadedModules, // link against a libc implementation. Preparing for libc linking (i.e. // linking with uClibc will expect a main function and rename it to // _user_main. We just provide the definition here. - if (!libCPrefix.empty()) - mainFn->getParent()->getOrInsertFunction(EntryPoint, - mainFn->getFunctionType()); + if (!libCPrefix.empty() && !mainFn->getParent()->getFunction(EntryPoint)) + llvm::Function::Create(mainFn->getFunctionType(), + llvm::Function::ExternalLinkage, EntryPoint, + mainFn->getParent()); llvm::Function *wrapper = nullptr; for (auto &module : loadedModules) { @@ -1067,7 +1068,7 @@ createLibCWrapper(std::vector<std::unique_ptr<llvm::Module>> &modules, if (!libcMainFn) klee_error("Could not add %s wrapper", libcMainFunction.str().c_str()); - auto inModuleRefernce = libcMainFn->getParent()->getOrInsertFunction( + auto inModuleReference = libcMainFn->getParent()->getOrInsertFunction( userMainFn->getName(), userMainFn->getFunctionType()); const auto ft = libcMainFn->getFunctionType(); @@ -1088,8 +1089,13 @@ createLibCWrapper(std::vector<std::unique_ptr<llvm::Module>> &modules, llvm::IRBuilder<> Builder(bb); std::vector<llvm::Value*> args; - args.push_back( - llvm::ConstantExpr::getBitCast(inModuleRefernce, ft->getParamType(0))); + args.push_back(llvm::ConstantExpr::getBitCast( +#if LLVM_VERSION_CODE >= LLVM_VERSION(9, 0) + cast<llvm::Constant>(inModuleReference.getCallee()), +#else + inModuleReference, +#endif + ft->getParamType(0))); args.push_back(&*(stub->arg_begin())); // argc auto arg_it = stub->arg_begin(); args.push_back(&*(++arg_it)); // argv |