Skip to content

Commit

Permalink
Analysis if which functions call error/errorcall.
Browse files Browse the repository at this point in the history
  • Loading branch information
kalibera committed Apr 10, 2017
1 parent 20ea996 commit 94f2d03
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/call.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

#include "call.h"

#include <llvm/IR/CallSite.h>
#include <llvm/IR/Constants.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Instruction.h>
#include <llvm/IR/BasicBlock.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/InstIterator.h>
#include <llvm/IR/Module.h>
#include <llvm/IRReader/IRReader.h>

#include <llvm/Support/raw_ostream.h>

#include <unordered_set>

using namespace llvm;

const bool DEBUG = false;

typedef std::unordered_set<Function*> FunctionSetTy;

bool mayCall(Function *src, Function *tgt, Function *ign, FunctionSetTy& analyzed) {
if (analyzed.find(src) != analyzed.end()) return false;
analyzed.insert(src);

if (src == tgt || src == ign) return false; // do not analyze tgt further

for(Function::iterator bb = src->begin(), bbe = src->end(); bb != bbe; ++bb) {
for(BasicBlock::iterator in = bb->begin(), ine = bb->end(); in != ine; ++in) {
Value *v = &*in;
CallSite cs(v);
if (!cs) continue;
Function *curtgt = cs.getCalledFunction();
if (!curtgt) continue;
if (curtgt == tgt || mayCall(curtgt, tgt, ign, analyzed)) {
errs() << " " << curtgt->getName() << " calls " << tgt->getName() << "\n";
return true;
}
}
}
return false;
}

bool mayCall(Function *src, Function *tgt, Function *ign) {

FunctionSetTy analyzed;
return mayCall(src, tgt, ign, analyzed);

}

10 changes: 10 additions & 0 deletions src/call.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef RENT_CALL_H
#define RENT_CALL_H

#include <llvm/IR/Function.h>

using namespace llvm;

bool mayCall(Function *src, Function *tgt, Function *ign);

#endif

0 comments on commit 94f2d03

Please sign in to comment.