50using namespace SVFUtil;
51using namespace cppUtil;
52using namespace LLVMUtil;
72 +
M.getName().str() +
"...\n"));
74 for (Module::const_global_iterator I =
M.global_begin(),
E =
M.global_end(); I !=
E; ++I)
76 for (Module::const_iterator F =
M.begin(),
E =
M.end(); F !=
E; ++F)
78 for (Module::const_iterator F =
M.begin(),
E =
M.end(); F !=
E; ++F)
106 assert(
vtbl &&
"Element of initializer not an array?");
139 for (Function::const_iterator
B = F->begin(),
E = F->end();
B !=
E; ++
B)
141 for (BasicBlock::const_iterator I =
B->begin(),
E =
B->end(); I !=
E; ++I)
147 else if (
const StoreInst *store = SVFUtil::dyn_cast<StoreInst>(&(*I)))
174 if (cs->arg_size() < 1 || (cs->arg_size() < 2 && cs->paramHasAttr(0, llvm::Attribute::StructRet)))
197 if (
ce->getOpcode() == Instruction::BitCast)
202 if (
bcce->getOpcode() == Instruction::GetElementPtr)
221 for (Module::const_named_metadata_iterator
mdit =
M.named_metadata_begin(),
225 string mdname =
md->getName().str();
226 if (
mdname.compare(0, 15,
"__cxx_bases_of_") != 0)
228 string className =
mdname.substr(15);
229 for (NamedMDNode::const_op_iterator
opit =
md->op_begin(),
233 const MDString*
mdstr = SVFUtil::cast<MDString>(
N->getOperand(0).get());
242 assert(!
chg->
getNode(className) &&
"this node should never be created before!");
246 if (className.size() > 0 && className[className.size() - 1] ==
'>')
277 while (!worklist.empty())
282 for (CHEdge::CHEdgeSetTy::const_iterator
it =
301 const string& className)
320 for (CHNodeSetTy::const_iterator
dit =
368 for (Module::const_global_iterator I =
M.global_begin(),
369 E =
M.global_end(); I !=
E; ++I)
378 assert(node &&
"node not found?");
388 SVFUtil::dyn_cast<ConstantArray>(
vtblStruct->getOperand(
ei));
389 assert(
vtbl &&
"Element of initializer not an array?");
404 for (;
i <
vtbl->getNumOperands(); ++
i)
407 if (SVFUtil::isa<ConstantPointerNull>(
operand))
409 if (
i > 0 && !SVFUtil::isa<ConstantPointerNull>(
vtbl->getOperand(
i-1)))
427 SVFUtil::dyn_cast<ConstantExpr>(
vtbl->getOperand(
i-1)))
429 if(
ce->getOpcode() == Instruction::BitCast)
430 foo(
ce->getOperand(0));
455 if (
dname.className.size() > 0 &&
465 SVFUtil::dyn_cast<GlobalAlias>(
operand))
478 "aliased constantexpr in vtable not a bitcast");
480 SVFUtil::dyn_cast<Function>(
aliasconst->getOperand(0));
482 "aliased bitcast in vtable not a function");
487 assert(
false &&
"alias not function or bitcast");
498 assert(
"what else can be in bitcast of a vtable?");
519 SVFUtil::dyn_cast<ConstantExpr>(
operand))
521 u32_t opcode =
ce->getOpcode();
522 assert(opcode == Instruction::IntToPtr);
524 "inttptr operand num not 1");
525 if (opcode == Instruction::IntToPtr)
574 string className = node->
getName();
581 nodeStack.push(node);
582 while (!nodeStack.empty())
589 for (CHEdge::CHEdgeSetTy::const_iterator
it =
curnode->getOutEdges().begin(),
596 for (CHEdge::CHEdgeSetTy::const_iterator
it =
curnode->getInEdges().begin(),
610 for (CHGraph::CHNodeSetTy::iterator
it =
group.begin(),
662 for (Module::const_iterator F =
M.begin(),
E =
M.end(); F !=
E; ++F)
666 if(
const CallBase* callInst = SVFUtil::dyn_cast<CallBase>(&*
II))
682 if (
vtbls.size() > 0)
717 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)
Map< const FunObjVar *, u32_t > virtualFunctionToIDMap
void addInstances(const std::string templateName, CHNode *node)
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)
virtual const std::string & getName() const
void setVTable(const GlobalObjVar *vtbl)
void setMultiInheritance()
void addVirtualFunctionVector(FuncVector vfuncvec)
const std::vector< FuncVector > & getVirtualFunctionVectors() const
void setPureAbstract()
Attribute.
std::vector< const FunObjVar * > FuncVector
void addGNode(NodeID id, NodeType *node)
Add a Node.
iterator begin()
Iterators.
IDToNodeMapTy::const_iterator const_iterator
NodeType * getGNode(NodeID id) const
Get a node.
const FunObjVar * getFunObjVar(const Function *fun) const
static LLVMModuleSet * getLLVMModuleSet()
ICFGNode * getICFGNode(const Instruction *inst)
Get a basic block ICFGNode.
NodeID getObjectNode(const Value *V)
const std::vector< std::reference_wrapper< Module > > & getLLVMModules() const
static const Option< bool > DumpCHA
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
static double getClk(bool mark=false)
NodeID getId() const
Get ID.
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 GlobalObjVar * > VTableSet
llvm::ConstantArray ConstantArray
llvm::GlobalValue GlobalValue
llvm::Value Value
LLVM Basic classes.
llvm::ConstantExpr ConstantExpr
llvm::IRBuilder IRBuilder
llvm::StoreInst StoreInst
Set< const FunObjVar * > VFunSet