Skip to content

Commit

Permalink
fix: potential endless recursion in hybrid instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrothenberger committed Aug 27, 2024
1 parent 7c063d6 commit 4e6f868
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions DiscoPoP/hybrid_analysis/InstructionCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ InstructionCFG::InstructionCFG(dputil::VariableNameFinder *_VNF, Function &F) :
}
// Add edges from last instruction in current block to first instruction all
// the successor blocks
if (previousInstruction != nullptr)
findAndAddFirstRelevantInstructionInSuccessorBlocks(&BB, previousInstruction);
if (previousInstruction != nullptr){
std::set<std::pair<BasicBlock*, Instruction*>> visited;
findAndAddFirstRelevantInstructionInSuccessorBlocks(&BB, previousInstruction, &visited);
}
}

// Conect entry/exit nodes
for (auto instNode : Graph::getInstructionNodes()) {
if (instNode != entry && instNode != exit) {
Expand All @@ -47,7 +48,17 @@ InstructionCFG::InstructionCFG(dputil::VariableNameFinder *_VNF, Function &F) :
}

void InstructionCFG::findAndAddFirstRelevantInstructionInSuccessorBlocks(BasicBlock *BB,
Instruction *previousInstruction) {
Instruction *previousInstruction,
std::set<std::pair<BasicBlock*, Instruction*>> *visited) {
// Check for and break out of cycles
std::pair<BasicBlock*, Instruction*> tmp_pair = std::make_pair(BB, previousInstruction);
const bool already_visited = visited->find(tmp_pair) != visited->end();
if(already_visited){
return;
}
// register visited node
visited->insert(tmp_pair);

bool hasSuccessors = false;
for (BasicBlock *S : successors(BB)) {
hasSuccessors = true;
Expand All @@ -62,8 +73,9 @@ void InstructionCFG::findAndAddFirstRelevantInstructionInSuccessorBlocks(BasicBl
Graph::addEdge(Graph::getInstructionNode(previousInstruction), exit);
}
}
if (S != BB)
findAndAddFirstRelevantInstructionInSuccessorBlocks(S, previousInstruction);
if (S != BB){
findAndAddFirstRelevantInstructionInSuccessorBlocks(S, previousInstruction, visited);
}
next:;
}
}
Expand Down
2 changes: 1 addition & 1 deletion DiscoPoP/hybrid_analysis/InstructionCFG.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class InstructionCFG : public Graph<Instruction *> {
dputil::VariableNameFinder *VNF;
set<Instruction *> highlightedInstructionNodes;

void findAndAddFirstRelevantInstructionInSuccessorBlocks(BasicBlock *BB, Instruction *previousInstruction);
void findAndAddFirstRelevantInstructionInSuccessorBlocks(BasicBlock *BB, Instruction *previousInstruction, std::set<std::pair<BasicBlock*, Instruction*>> *visited);

public:
InstructionCFG(dputil::VariableNameFinder *_VNF, Function &F);
Expand Down

0 comments on commit 4e6f868

Please sign in to comment.