From b7a6aec4eeb4cbbc71d4747d2aa6d25dda41d5d1 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Thu, 23 Feb 2017 17:41:33 +0100 Subject: convert iterators using static_cast Newer versions of LLVM do not allow to implicitly cast iterators to pointers where they point. So convert all such uses to explicit static_cast, the same as LLVM code does. Otherwise we see errors like: lib/Core/Executor.cpp:548:15: error: no viable conversion from 'Module::iterator' (aka 'ilist_iterator') to 'llvm::Function *' Function *f = i; ^ ~ Signed-off-by: Jiri Slaby --- lib/Module/Checks.cpp | 4 ++-- lib/Module/InstructionInfoTable.cpp | 8 ++++---- lib/Module/KModule.cpp | 25 ++++++++++++++----------- lib/Module/LowerSwitch.cpp | 3 ++- lib/Module/RaiseAsm.cpp | 2 +- 5 files changed, 23 insertions(+), 19 deletions(-) (limited to 'lib/Module') diff --git a/lib/Module/Checks.cpp b/lib/Module/Checks.cpp index 44b35e6e..48a4eb94 100644 --- a/lib/Module/Checks.cpp +++ b/lib/Module/Checks.cpp @@ -71,7 +71,7 @@ bool DivCheckPass::runOnModule(Module &M) { Type::getInt64Ty(ctx), false, /* sign doesn't matter */ "int_cast_to_i64", - i); + static_cast(i)); // Lazily bind the function to avoid always importing it. if (!divZeroCheckFunction) { @@ -129,7 +129,7 @@ bool OvershiftCheckPass::runOnModule(Module &M) { Type::getInt64Ty(ctx), false, /* sign doesn't matter */ "int_cast_to_i64", - i); + static_cast(i)); args.push_back(shift); diff --git a/lib/Module/InstructionInfoTable.cpp b/lib/Module/InstructionInfoTable.cpp index 7e9a9e26..adf05442 100644 --- a/lib/Module/InstructionInfoTable.cpp +++ b/lib/Module/InstructionInfoTable.cpp @@ -120,6 +120,7 @@ InstructionInfoTable::InstructionInfoTable(Module *m) for (Module::iterator fnIt = m->begin(), fn_ie = m->end(); fnIt != fn_ie; ++fnIt) { + Function *fn = static_cast(fnIt); // We want to ensure that as all instructions have source information, if // available. Clang sometimes will not write out debug information on the @@ -128,15 +129,14 @@ InstructionInfoTable::InstructionInfoTable(Module *m) // if any. const std::string *initialFile = &dummyString; unsigned initialLine = 0; - for (inst_iterator it = inst_begin(fnIt), ie = inst_end(fnIt); it != ie; - ++it) { + for (inst_iterator it = inst_begin(fn), ie = inst_end(fn); it != ie; ++it) { if (getInstructionDebugInfo(&*it, initialFile, initialLine)) break; } const std::string *file = initialFile; unsigned line = initialLine; - for (inst_iterator it = inst_begin(fnIt), ie = inst_end(fnIt); it != ie; + for (inst_iterator it = inst_begin(fn), ie = inst_end(fn); it != ie; ++it) { Instruction *instr = &*it; unsigned assemblyLine = lineTable[instr]; @@ -193,6 +193,6 @@ InstructionInfoTable::getFunctionInfo(const Function *f) const { // and construct a test case for it if it does, though. return dummyInfo; } else { - return getInfo(f->begin()->begin()); + return getInfo(static_cast(f->begin()->begin())); } } diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp index 3259873e..08ec28ef 100644 --- a/lib/Module/KModule.cpp +++ b/lib/Module/KModule.cpp @@ -190,7 +190,7 @@ static void injectStaticConstructorsAndDestructors(Module *m) { if (ctors) CallInst::Create(getStubFunctionForCtorList(m, ctors, "klee.ctor_stub"), - "", mainFn->begin()->begin()); + "", static_cast(mainFn->begin()->begin())); if (dtors) { Function *dtorStub = getStubFunctionForCtorList(m, dtors, "klee.dtor_stub"); for (Function::iterator it = mainFn->begin(), ie = mainFn->end(); @@ -280,14 +280,15 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts, llvm::errs() << "KLEE: adding klee_merge at exit of: " << name << "\n"; for (llvm::Function::iterator bbit = f->begin(), bbie = f->end(); bbit != bbie; ++bbit) { - if (&*bbit != exit) { + BasicBlock *bb = static_cast(bbit); + if (bb != exit) { Instruction *i = bbit->getTerminator(); if (i->getOpcode()==Instruction::Ret) { if (result) { - result->addIncoming(i->getOperand(0), bbit); + result->addIncoming(i->getOperand(0), bb); } i->eraseFromParent(); - BranchInst::Create(exit, bbit); + BranchInst::Create(exit, bb); } } } @@ -444,7 +445,8 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts, if (it->isDeclaration()) continue; - KFunction *kf = new KFunction(it, this); + Function *fn = static_cast(it); + KFunction *kf = new KFunction(fn, this); for (unsigned i=0; inumInstructions; ++i) { KInstruction *ki = kf->instructions[i]; @@ -452,7 +454,7 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts, } functions.push_back(kf); - functionMap.insert(std::make_pair(it, kf)); + functionMap.insert(std::make_pair(fn, kf)); } /* Compute various interesting properties */ @@ -529,7 +531,7 @@ KFunction::KFunction(llvm::Function *_function, trackCoverage(true) { for (llvm::Function::iterator bbit = function->begin(), bbie = function->end(); bbit != bbie; ++bbit) { - BasicBlock *bb = bbit; + BasicBlock *bb = static_cast(bbit); basicBlockEntry[bb] = numInstructions; numInstructions += bb->size(); } @@ -544,7 +546,7 @@ KFunction::KFunction(llvm::Function *_function, bbie = function->end(); bbit != bbie; ++bbit) { for (llvm::BasicBlock::iterator it = bbit->begin(), ie = bbit->end(); it != ie; ++it) - registerMap[it] = rnum++; + registerMap[static_cast(it)] = rnum++; } numRegisters = rnum; @@ -564,11 +566,12 @@ KFunction::KFunction(llvm::Function *_function, ki = new KInstruction(); break; } - ki->inst = it; - ki->dest = registerMap[it]; + Instruction *inst = static_cast(it); + ki->inst = inst; + ki->dest = registerMap[inst]; if (isa(it) || isa(it)) { - CallSite cs(it); + CallSite cs(inst); unsigned numArgs = cs.arg_size(); ki->operands = new int[numArgs+1]; ki->operands[0] = getOperandNum(cs.getCalledValue(), registerMap, km, diff --git a/lib/Module/LowerSwitch.cpp b/lib/Module/LowerSwitch.cpp index 7f28748a..5cc6b991 100644 --- a/lib/Module/LowerSwitch.cpp +++ b/lib/Module/LowerSwitch.cpp @@ -44,7 +44,8 @@ bool LowerSwitchPass::runOnFunction(Function &F) { bool changed = false; for (Function::iterator I = F.begin(), E = F.end(); I != E; ) { - BasicBlock *cur = I++; // Advance over block so we don't traverse new blocks + BasicBlock *cur = static_cast(I); + I++; // Advance over block so we don't traverse new blocks if (SwitchInst *SI = dyn_cast(cur->getTerminator())) { changed = true; diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp index e612ca63..af92b74b 100644 --- a/lib/Module/RaiseAsm.cpp +++ b/lib/Module/RaiseAsm.cpp @@ -115,7 +115,7 @@ bool RaiseAsmPass::runOnModule(Module &M) { for (Module::iterator fi = M.begin(), fe = M.end(); fi != fe; ++fi) { for (Function::iterator bi = fi->begin(), be = fi->end(); bi != be; ++bi) { for (BasicBlock::iterator ii = bi->begin(), ie = bi->end(); ii != ie;) { - Instruction *i = ii; + Instruction *i = static_cast(ii); ++ii; changed |= runOnInstruction(M, i); } -- cgit 1.4.1