-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Analysis if which functions call error/errorcall.
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |