From e32ae5ae50165593b82cffb6e946532618000933 Mon Sep 17 00:00:00 2001 From: Julian Büning Date: Wed, 17 Jul 2019 22:42:12 +0200 Subject: support compilation against LLVM 9.0 --- lib/Module/Checks.cpp | 8 ++++---- lib/Module/IntrinsicCleaner.cpp | 17 +++++++++++------ lib/Module/KModule.cpp | 9 +++++++-- 3 files changed, 22 insertions(+), 12 deletions(-) (limited to 'lib/Module') 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( + 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(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( - 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(C.getCallee())) { +#else + if (auto *F = dyn_cast(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; igetNumOperands(); i++) { auto cs = cast(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(fp)) -- cgit 1.4.1