diff --git a/include/klee/Module/KModule.h b/include/klee/Module/KModule.h index 4965f78b27..50949908b6 100644 --- a/include/klee/Module/KModule.h +++ b/include/klee/Module/KModule.h @@ -60,8 +60,6 @@ enum KBlockType { Base, Call, Return }; struct KBlock { KFunction *parent; llvm::BasicBlock *basicBlock; - - unsigned numInstructions; KInstruction **instructions; public: @@ -76,9 +74,10 @@ struct KBlock { virtual KBlockType getKBlockType() const { return KBlockType::Base; } static bool classof(const KBlock *) { return true; } + unsigned getNumInstructions() const noexcept { return basicBlock->size(); } KInstruction *getFirstInstruction() const noexcept { return instructions[0]; } KInstruction *getLastInstruction() const noexcept { - return instructions[numInstructions - 1]; + return instructions[getNumInstructions() - 1]; } std::string getLabel() const; std::string toString() const; diff --git a/lib/Core/Searcher.cpp b/lib/Core/Searcher.cpp index 08e725eacb..644d5904a0 100644 --- a/lib/Core/Searcher.cpp +++ b/lib/Core/Searcher.cpp @@ -189,7 +189,7 @@ weight_type TargetedSearcher::getWeight(ExecutionState *es) { KBlock *kb = es->pc->parent; KInstruction *ki = es->pc; weight_type weight; - if (!target->shouldFailOnThisTarget() && kb->numInstructions && + if (!target->shouldFailOnThisTarget() && kb->getNumInstructions() && !isa(kb) && kb->getFirstInstruction() != ki && states->tryGetWeight(es, weight)) { return weight; diff --git a/lib/Core/TypeManager.cpp b/lib/Core/TypeManager.cpp index c6e00f2f82..0ba8f8ffb1 100644 --- a/lib/Core/TypeManager.cpp +++ b/lib/Core/TypeManager.cpp @@ -141,20 +141,13 @@ void TypeManager::initTypesFromGlobals() { */ void TypeManager::initTypesFromInstructions() { for (auto &function : *(parent->module)) { - auto kf = parent->functionMap[&function]; - for (auto &BasicBlock : function) { - unsigned numInstructions = kf->blockMap[&BasicBlock]->numInstructions; - KBlock *kb = kf->blockMap[&BasicBlock]; - - for (unsigned i = 0; i < numInstructions; ++i) { - llvm::Instruction *inst = kb->instructions[i]->inst; - + for (auto &inst : BasicBlock) { /* Register return type */ - getWrappedType(inst->getType()); + getWrappedType(inst.getType()); /* Register types for arguments */ - for (auto opb = inst->op_begin(), ope = inst->op_end(); opb != ope; + for (auto opb = inst.op_begin(), ope = inst.op_end(); opb != ope; ++opb) { getWrappedType((*opb)->getType()); } diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp index 7bfb8433f3..946fd2f087 100644 --- a/lib/Module/KModule.cpp +++ b/lib/Module/KModule.cpp @@ -606,7 +606,7 @@ KFunction::KFunction(llvm::Function *_function, KModule *_km, kb = new KBlock(this, &*bbit, parent, instructionToRegisterMap, &instructions[n], globalIndexInc); } - for (unsigned i = 0; i < kb->numInstructions; i++, n++) { + for (unsigned i = 0, ie = kb->getNumInstructions(); i < ie; i++, n++) { instructionMap[instructions[n]->inst] = instructions[n]; } blockMap[&*bbit] = kb; @@ -639,8 +639,7 @@ KBlock::KBlock( KFunction *_kfunction, llvm::BasicBlock *block, KModule *km, const std::unordered_map &instructionToRegisterMap, KInstruction **instructionsKF, unsigned &globalIndexInc) - : parent(_kfunction), basicBlock(block), numInstructions(0) { - numInstructions += block->size(); + : parent(_kfunction), basicBlock(block) { instructions = instructionsKF; for (auto &it : *block) { diff --git a/lib/Module/SarifReport.cpp b/lib/Module/SarifReport.cpp index 3923d32ead..6cc323a87a 100644 --- a/lib/Module/SarifReport.cpp +++ b/lib/Module/SarifReport.cpp @@ -333,7 +333,7 @@ bool Location::isInside(KBlock *block, const Instructions &origInsts) const { return false; return startLine <= last->getLine(); // and `first <= line` from above } else { - for (size_t i = 0; i < block->numInstructions; ++i) { + for (unsigned i = 0, ie = block->getNumInstructions(); i < ie; ++i) { auto inst = block->instructions[i]; auto opCode = block->instructions[i]->inst->getOpcode(); if (!isa(block->instructions[i]->inst) &&