51using namespace SVFUtil;
52using namespace cppUtil;
53using namespace LLVMUtil;
73 +
M.getName().str() +
"...\n"));
75 for (Module::const_global_iterator I =
M.global_begin(),
E =
M.global_end(); I !=
E; ++I)
77 for (Module::const_iterator
F =
M.begin(),
E =
M.end();
F !=
E; ++
F)
79 for (Module::const_iterator
F =
M.begin(),
E =
M.end();
F !=
E; ++
F)
107 assert(
vtbl &&
"Element of initializer not an array?");
140 for (Function::const_iterator
B =
F->begin(),
E =
F->end();
B !=
E; ++
B)
142 for (BasicBlock::const_iterator I =
B->begin(),
E =
B->end(); I !=
E; ++I)
148 else if (
const StoreInst *store = SVFUtil::dyn_cast<StoreInst>(&(*I)))
175 if (cs->arg_size() < 1 || (cs->arg_size() < 2 && cs->paramHasAttr(0, llvm::Attribute::StructRet)))
198 if (
ce->getOpcode() == Instruction::BitCast)
203 if (
bcce->getOpcode() == Instruction::GetElementPtr)
222 for (Module::const_named_metadata_iterator
mdit =
M.named_metadata_begin(),
226 string mdname =
md->getName().str();
227 if (
mdname.compare(0, 15,
"__cxx_bases_of_") != 0)
229 string className =
mdname.substr(15);
230 for (NamedMDNode::const_op_iterator
opit =
md->op_begin(),
234 const MDString*
mdstr = SVFUtil::cast<MDString>(
N->getOperand(0).get());
243 assert(!
chg->
getNode(className) &&
"this node should never be created before!");
247 if (className.size() > 0 && className[className.size() - 1] ==
'>')
278 while (!worklist.empty())
283 for (CHEdge::CHEdgeSetTy::const_iterator
it =
302 const string& className)
321 for (CHNodeSetTy::const_iterator
dit =
369 for (Module::const_global_iterator I =
M.global_begin(),
370 E =
M.global_end(); I !=
E; ++I)
379 assert(node &&
"node not found?");
390 SVFUtil::dyn_cast<ConstantArray>(
vtblStruct->getOperand(
ei));
391 assert(
vtbl &&
"Element of initializer not an array?");
406 for (;
i <
vtbl->getNumOperands(); ++
i)
409 if (SVFUtil::isa<ConstantPointerNull>(
operand))
411 if (
i > 0 && !SVFUtil::isa<ConstantPointerNull>(
vtbl->getOperand(
i-1)))
429 SVFUtil::dyn_cast<ConstantExpr>(
vtbl->getOperand(
i-1)))
431 if(
ce->getOpcode() == Instruction::BitCast)
432 foo(
ce->getOperand(0));
457 if (
dname.className.size() > 0 &&
467 SVFUtil::dyn_cast<GlobalAlias>(
operand))
480 "aliased constantexpr in vtable not a bitcast");
482 SVFUtil::dyn_cast<Function>(
aliasconst->getOperand(0));
484 "aliased bitcast in vtable not a function");
489 assert(
false &&
"alias not function or bitcast");
500 assert(
"what else can be in bitcast of a vtable?");
521 SVFUtil::dyn_cast<ConstantExpr>(
operand))
523 u32_t opcode =
ce->getOpcode();
524 assert(opcode == Instruction::IntToPtr);
526 "inttptr operand num not 1");
527 if (opcode == Instruction::IntToPtr)
576 string className = node->
getName();
583 nodeStack.push(node);
584 while (!nodeStack.empty())
591 for (CHEdge::CHEdgeSetTy::const_iterator
it =
curnode->getOutEdges().begin(),
598 for (CHEdge::CHEdgeSetTy::const_iterator
it =
curnode->getInEdges().begin(),
612 for (CHGraph::CHNodeSetTy::iterator
it =
group.begin(),
664 for (Module::const_iterator
F =
M.begin(),
E =
M.end();
F !=
E; ++
F)
668 if(
const CallBase* callInst = SVFUtil::dyn_cast<CallBase>(&*
II))
684 if (
vtbls.size() > 0)
719 for (
const auto &node: *
chg)
const string pureVirtualFunName
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) add_llvm_executable(wpa wpa.cpp) target_link_libraries(wpa PUBLIC $
void analyzeVTables(const Module &M)
void connectInheritEdgeViaStore(const Function *caller, const StoreInst *store)
LLVMModuleSet * llvmModuleSet()
void readInheritanceMetadataFromModule(const Module &M)
void buildCHGNodes(const GlobalValue *V)
const CHGraph::CHNodeSetTy & getInstancesAndDescendants(const std::string &className)
CHGraph::WorkList WorkList
void addFuncToFuncVector(CHNode::FuncVector &v, const Function *f)
void buildCHGEdges(const Function *F)
void buildVirtualFunctionToIDMap()
void buildCSToCHAVtblsAndVfnsMap()
CHGraph::CHNodeSetTy CHNodeSetTy
const CHNodeSetTy & getCSClasses(const CallBase *cs)
CHNode * createNode(const std::string &name)
void connectInheritEdgeViaCall(const Function *caller, const CallBase *cs)
void buildClassNameToAncestorsDescendantsMap()
NameToCHNodesMap classNameToAncestorsMap
CallNodeToCHNodesMap callNodeToClassesMap
CallNodeToVFunSetMap callNodeToCHAVFnsMap
void dump(const std::string &filename)
const CHNodeSetTy & getInstances(const std::string className)
void addEdge(const std::string className, const std::string baseClassName, CHEdge::CHEDGETYPE edgeType)
void addInstances(const std::string templateName, CHNode *node)
Map< const SVFFunction *, u32_t > virtualFunctionToIDMap
void getVFnsFromVtbls(const CallICFGNode *cs, const VTableSet &vtbls, VFunSet &virtualFunctions) override
CHNode * getNode(const std::string name) const
NameToCHNodesMap classNameToInstAndDescsMap
NameToCHNodesMap classNameToDescendantsMap
Set< const CHNode * > CHNodeSetTy
Map< std::string, CHNode * > classNameToNodeMap
CallNodeToVTableSetMap callNodeToCHAVtblsMap
const CHNodeSetTy & getDescendants(const std::string className)
void setMultiInheritance()
void addVirtualFunctionVector(FuncVector vfuncvec)
std::vector< const SVFFunction * > FuncVector
const std::vector< FuncVector > & getVirtualFunctionVectors() const
void setVTable(const SVFGlobalValue *vtbl)
void setPureAbstract()
Attribute.
std::string getName() const
void addGNode(NodeID id, NodeType *node)
Add a Node.
iterator begin()
Iterators.
IDToNodeMapTy::const_iterator const_iterator
static LLVMModuleSet * getLLVMModuleSet()
ICFGNode * getICFGNode(const Instruction *inst)
Get a basic block ICFGNode.
SVFFunction * getSVFFunction(const Function *fun) const
const std::vector< std::reference_wrapper< Module > > & getLLVMModules() const
SVFGlobalValue * getSVFGlobalValue(const GlobalValue *g) const
static const Option< bool > DumpCHA
NodeID getId() const
Get ID.
static double getClk(bool mark=false)
void setName(const std::string &n)
bool isCallSite(const Instruction *inst)
Whether an instruction is a call or invoke instruction.
const ConstantExpr * isCastConstantExpr(const Value *val)
const Function * getCallee(const CallBase *cs)
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
std::ostream & outs()
Overwrite llvm::outs()
std::string getBeforeBrackets(const std::string &name)
const Value * getVCallThisPtr(const CallBase *cs)
struct DemangledName demangle(const std::string &name)
Set< std::string > getClassNameOfThisPtr(const CallBase *cs)
bool isCPPThunkFunction(const Function *F)
bool isVirtualCallSite(const CallBase *cs)
const Function * getThunkTarget(const Function *F)
const ConstantStruct * getVtblStruct(const GlobalValue *vtbl)
bool isConstructor(const Function *F)
std::string getClassNameFromVtblObj(const std::string &vtblName)
bool isValVtbl(const Value *val)
bool isDestructor(const Function *F)
llvm::const_inst_iterator const_inst_iterator
llvm::GlobalAlias GlobalAlias
llvm::ConstantStruct ConstantStruct
llvm::NamedMDNode NamedMDNode
LLVM metadata and debug information.
Set< const SVFGlobalValue * > VTableSet
llvm::ConstantArray ConstantArray
llvm::GlobalValue GlobalValue
llvm::Value Value
LLVM Basic classes.
llvm::ConstantExpr ConstantExpr
llvm::IRBuilder IRBuilder
llvm::StoreInst StoreInst
Set< const SVFFunction * > VFunSet