diff --git a/svf-llvm/lib/CHGBuilder.cpp b/svf-llvm/lib/CHGBuilder.cpp index 276856071..5d89ac641 100644 --- a/svf-llvm/lib/CHGBuilder.cpp +++ b/svf-llvm/lib/CHGBuilder.cpp @@ -679,7 +679,7 @@ void CHGBuilder::buildCSToCHAVtblsAndVfnsMap() } if (vtbls.size() > 0) { - CallSite cs = SVFUtil::getSVFCallSite(LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction(callInst)); + CallSite cs(LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction(callInst)); chg->csToCHAVtblsMap[cs] = vtbls; VFunSet virtualFunctions; chg->getVFnsFromVtbls(cs, vtbls, virtualFunctions); diff --git a/svf-llvm/lib/SVFIRExtAPI.cpp b/svf-llvm/lib/SVFIRExtAPI.cpp index fb19d7f16..a206e760d 100644 --- a/svf-llvm/lib/SVFIRExtAPI.cpp +++ b/svf-llvm/lib/SVFIRExtAPI.cpp @@ -125,6 +125,7 @@ void SVFIRBuilder::handleExtCall(const CallBase* cs, const SVFFunction* svfCalle { const SVFInstruction* svfInst = LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction(cs); const SVFCallInst* svfCall = SVFUtil::cast(svfInst); + const CallICFGNode *callICFGNode = pag->getICFG()->getCallICFGNode(svfInst); if (isHeapAllocExtCallViaRet(svfCall)) { @@ -253,12 +254,12 @@ void SVFIRBuilder::handleExtCall(const CallBase* cs, const SVFFunction* svfCalle } } - if (isThreadForkCall(svfInst)) + if (isThreadForkCall(callICFGNode)) { - if (const SVFFunction* forkedFun = SVFUtil::dyn_cast(getForkedFun(svfInst))) + if (const SVFFunction* forkedFun = SVFUtil::dyn_cast(getForkedFun(callICFGNode))) { forkedFun = forkedFun->getDefFunForMultipleModule(); - const SVFValue* actualParm = getActualParmAtForkSite(svfInst); + const SVFValue* actualParm = getActualParmAtForkSite(callICFGNode); /// pthread_create has 1 arg. /// apr_thread_create has 2 arg. assert((forkedFun->arg_size() <= 2) && "Size of formal parameter of start routine should be one"); @@ -268,9 +269,8 @@ void SVFIRBuilder::handleExtCall(const CallBase* cs, const SVFFunction* svfCalle /// Connect actual parameter to formal parameter of the start routine if (actualParm->getType()->isPointerTy() && formalParm->getType()->isPointerTy()) { - CallICFGNode *icfgNode = pag->getICFG()->getCallICFGNode(svfInst); FunEntryICFGNode *entry = pag->getICFG()->getFunEntryICFGNode(forkedFun); - addThreadForkEdge(pag->getValueNode(actualParm), pag->getValueNode(formalParm), icfgNode, entry); + addThreadForkEdge(pag->getValueNode(actualParm), pag->getValueNode(formalParm), callICFGNode, entry); } } } diff --git a/svf-llvm/lib/SymbolTableBuilder.cpp b/svf-llvm/lib/SymbolTableBuilder.cpp index ba82e122c..c1b14eedc 100644 --- a/svf-llvm/lib/SymbolTableBuilder.cpp +++ b/svf-llvm/lib/SymbolTableBuilder.cpp @@ -608,7 +608,7 @@ const Type* SymbolTableBuilder::inferTypeOfHeapObjOrStaticObj(const Instruction else if(SVFUtil::isHeapAllocExtCallViaArg(svfinst)) { const CallBase* cs = LLVMUtil::getLLVMCallSite(inst); - int arg_pos = SVFUtil::getHeapAllocHoldingArgPosition(SVFUtil::getSVFCallSite(svfinst)); + int arg_pos = SVFUtil::getHeapAllocHoldingArgPosition(getCallee(svfinst)); const Value* arg = cs->getArgOperand(arg_pos); originalPType = SVFUtil::dyn_cast(arg->getType()); inferedType = inferObjType(startValue = arg); diff --git a/svf/include/Util/SVFUtil.h b/svf/include/Util/SVFUtil.h index eddb2b9dd..7d44a0922 100644 --- a/svf/include/Util/SVFUtil.h +++ b/svf/include/Util/SVFUtil.h @@ -169,14 +169,8 @@ void dumpPointsToList(const PointsToList& ptl); /// Return true if it is an llvm intrinsic instruction bool isIntrinsicInst(const SVFInstruction* inst); bool isIntrinsicInst(const ICFGNode* inst); - //@} -/// Whether an instruction is a call or invoke instruction -inline bool isCallSite(const SVFInstruction* inst) -{ - return SVFUtil::isa(inst); -} /// Whether an instruction is a call or invoke instruction inline bool isCallSite(const SVFValue* val) { @@ -207,31 +201,15 @@ inline bool isNonInstricCallSite(const ICFGNode* inst) } - /// Return callsite given an instruction CallSite getSVFCallSite(const ICFGNode* inst); -/// Return callsite given an instruction -inline CallSite getSVFCallSite(const SVFInstruction* inst) -{ - assert(isCallSite(inst) && "not a callsite?"); - CallSite cs(inst); - return cs; -} /// Match arguments for callsite at caller and callee /// if the arg size does not match then we do not need to connect this parameter /// unless the callee is a variadic function (the first parameter of variadic function is its parameter number) -bool matchArgs(const CallSite cs, const SVFFunction* callee); +bool matchArgs(const CallICFGNode* cs, const SVFFunction* callee); -/// Return LLVM callsite given a value -inline CallSite getSVFCallSite(const SVFValue* value) -{ - assert(isCallSite(value) && "not a callsite?"); - const SVFCallInst* svfInst = SVFUtil::cast(value); - CallSite cs(svfInst); - return cs; -} /// Split into two substrings around the first occurrence of a separator string. inline std::vector split(const std::string& s, char separator) @@ -423,7 +401,7 @@ inline bool isArgOfUncalledFunction(const SVFValue* svfval) /// Return thread fork function //@{ -inline const SVFValue* getForkedFun(const SVFInstruction *inst) +inline const SVFValue* getForkedFun(const ICFGNode *inst) { return ThreadAPI::getThreadAPI()->getForkedFun(inst); } @@ -488,7 +466,7 @@ inline bool isReallocExtCall(const CallSite cs) /// Return true if this is a thread creation call ///@{ -inline bool isThreadForkCall(const SVFInstruction *inst) +inline bool isThreadForkCall(const ICFGNode *inst) { return ThreadAPI::getThreadAPI()->isTDFork(inst); } @@ -496,49 +474,49 @@ inline bool isThreadForkCall(const SVFInstruction *inst) /// Return true if this is a thread join call ///@{ -inline bool isThreadJoinCall(const CallSite cs) +inline bool isThreadJoinCall(const ICFGNode* cs) { - return ThreadAPI::getThreadAPI()->isTDJoin(cs.getInstruction()); + return ThreadAPI::getThreadAPI()->isTDJoin(cs); } //@} /// Return true if this is a thread exit call ///@{ -inline bool isThreadExitCall(const CallSite cs) +inline bool isThreadExitCall(const ICFGNode* cs) { - return ThreadAPI::getThreadAPI()->isTDExit(cs.getInstruction()); + return ThreadAPI::getThreadAPI()->isTDExit(cs); } //@} /// Return true if this is a lock acquire call ///@{ -inline bool isLockAquireCall(const CallSite cs) +inline bool isLockAquireCall(const ICFGNode* cs) { - return ThreadAPI::getThreadAPI()->isTDAcquire(cs.getInstruction()); + return ThreadAPI::getThreadAPI()->isTDAcquire(cs); } //@} /// Return true if this is a lock acquire call ///@{ -inline bool isLockReleaseCall(const CallSite cs) +inline bool isLockReleaseCall(const ICFGNode* cs) { - return ThreadAPI::getThreadAPI()->isTDRelease(cs.getInstruction()); + return ThreadAPI::getThreadAPI()->isTDRelease(cs); } //@} /// Return true if this is a barrier wait call //@{ -inline bool isBarrierWaitCall(const CallSite cs) +inline bool isBarrierWaitCall(const ICFGNode* cs) { - return ThreadAPI::getThreadAPI()->isTDBarWait(cs.getInstruction()); + return ThreadAPI::getThreadAPI()->isTDBarWait(cs); } //@} /// Return sole argument of the thread routine //@{ -inline const SVFValue* getActualParmAtForkSite(const CallSite cs) +inline const SVFValue* getActualParmAtForkSite(const ICFGNode* cs) { - return ThreadAPI::getThreadAPI()->getActualParmAtForkSite(cs.getInstruction()); + return ThreadAPI::getThreadAPI()->getActualParmAtForkSite(cs); } //@} diff --git a/svf/include/Util/ThreadAPI.h b/svf/include/Util/ThreadAPI.h index 63b4c49ec..1605b01ea 100644 --- a/svf/include/Util/ThreadAPI.h +++ b/svf/include/Util/ThreadAPI.h @@ -37,6 +37,7 @@ namespace SVF class SVFModule; class ICFGNode; +class CallICFGNode; /* * ThreadAPI class contains interfaces for pthread programs @@ -121,8 +122,6 @@ class ThreadAPI /// Return the callee/callsite/func //@{ const SVFFunction* getCallee(const ICFGNode *inst) const; - const SVFFunction* getCallee(const SVFInstruction *inst) const; - const CallSite getSVFCallSite(const SVFInstruction *inst) const; const CallSite getSVFCallSite(const ICFGNode *inst) const; //@} @@ -132,10 +131,6 @@ class ThreadAPI { return getType(getCallee(inst)) == TD_FORK; } - inline bool isTDFork(const SVFInstruction* cs) const - { - return getType(getCallee(cs)) == TD_FORK; - } //@} /// Return arguments/attributes of pthread_create / hare_parallel_for @@ -148,13 +143,6 @@ class ThreadAPI CallSite cs = getSVFCallSite(inst); return cs.getArgument(0); } - inline const SVFValue* getForkedThread(const SVFInstruction* inst) const - { - assert(isTDFork(inst) && "not a thread fork function!"); - CallSite cs = getSVFCallSite(inst); - return cs.getArgument(0); - } - /// Return the third argument of the call, /// Note that, it could be function type or a void* pointer inline const SVFValue* getForkedFun(const ICFGNode *inst) const @@ -163,12 +151,6 @@ class ThreadAPI CallSite cs = getSVFCallSite(inst); return cs.getArgument(2); } - inline const SVFValue* getForkedFun(const SVFInstruction* inst) const - { - assert(isTDFork(inst) && "not a thread fork function!"); - CallSite cs = getSVFCallSite(inst); - return cs.getArgument(2); - } /// Return the forth argument of the call, /// Note that, it is the sole argument of start routine ( a void* pointer ) @@ -178,12 +160,6 @@ class ThreadAPI CallSite cs = getSVFCallSite(inst); return cs.getArgument(3); } - inline const SVFValue* getActualParmAtForkSite(const SVFInstruction* inst) const - { - assert(isTDFork(inst) && "not a thread fork function!"); - CallSite cs = getSVFCallSite(inst); - return cs.getArgument(3); - } //@} /// Return true if this call wait for a worker thread @@ -192,10 +168,6 @@ class ThreadAPI { return getType(getCallee(inst)) == TD_JOIN; } - inline bool isTDJoin(const SVFInstruction* inst) const - { - return getType(getCallee(inst)) == TD_JOIN; - } //@} /// Return arguments/attributes of pthread_join @@ -211,12 +183,6 @@ class ThreadAPI CallSite cs = getSVFCallSite(inst); return cs.getArgument(1); } - inline const SVFValue* getRetParmAtJoinedSite(const SVFInstruction* inst) const - { - assert(isTDJoin(inst) && "not a thread join function!"); - CallSite cs = getSVFCallSite(inst); - return cs.getArgument(1); - } //@} @@ -226,11 +192,6 @@ class ThreadAPI { return getType(getCallee(inst)) == TD_EXIT; } - - inline bool isTDExit(const SVFInstruction* inst) const - { - return getType(getCallee(inst)) == TD_EXIT; - } //@} /// Return true if this call acquire a lock @@ -239,11 +200,6 @@ class ThreadAPI { return getType(getCallee(inst)) == TD_ACQUIRE; } - - inline bool isTDAcquire(const SVFInstruction* inst) const - { - return getType(getCallee(inst)) == TD_ACQUIRE; - } //@} /// Return true if this call release a lock @@ -252,11 +208,6 @@ class ThreadAPI { return getType(getCallee(inst)) == TD_RELEASE; } - - inline bool isTDRelease(const SVFInstruction* inst) const - { - return getType(getCallee(inst)) == TD_RELEASE; - } //@} /// Return lock value @@ -271,11 +222,6 @@ class ThreadAPI { return getType(getCallee(inst)) == TD_BAR_WAIT; } - - inline bool isTDBarWait(const SVFInstruction* inst) const - { - return getType(getCallee(inst)) == TD_BAR_WAIT; - } //@} void performAPIStat(SVFModule* m); diff --git a/svf/lib/AE/Svfexe/AEDetector.cpp b/svf/lib/AE/Svfexe/AEDetector.cpp index 78fb8888f..4bd4501f9 100644 --- a/svf/lib/AE/Svfexe/AEDetector.cpp +++ b/svf/lib/AE/Svfexe/AEDetector.cpp @@ -148,7 +148,7 @@ void BufOverflowDetector::detectExtAPI(AbstractState& as, SVFIR* svfir = PAG::getPAG(); const SVFFunction *fun = SVFUtil::getCallee(call->getCallSite()); assert(fun && "SVFFunction* is nullptr"); - CallSite cs = SVFUtil::getSVFCallSite(call->getCallSite()); + CallSite cs = SVFUtil::getSVFCallSite(call); AbstractInterpretation::ExtAPIType extType = AbstractInterpretation::UNCLASSIFIED; @@ -322,7 +322,7 @@ void BufOverflowDetector::updateGepObjOffsetFromBase(SVF::AddressValue gepAddrs, */ bool BufOverflowDetector::detectStrcpy(AbstractState& as, const CallICFGNode *call) { - CallSite cs = SVFUtil::getSVFCallSite(call->getCallSite()); + CallSite cs = SVFUtil::getSVFCallSite(call); const SVFValue* arg0Val = cs.getArgument(0); const SVFValue* arg1Val = cs.getArgument(1); IntervalValue strLen = AbstractInterpretation::getAEInstance().getStrlen(as, arg1Val); @@ -349,7 +349,7 @@ bool BufOverflowDetector::detectStrcat(AbstractState& as, const CallICFGNode *ca if (std::find(strcatGroup.begin(), strcatGroup.end(), fun->getName()) != strcatGroup.end()) { - CallSite cs = SVFUtil::getSVFCallSite(call->getCallSite()); + CallSite cs = SVFUtil::getSVFCallSite(call); const SVFValue* arg0Val = cs.getArgument(0); const SVFValue* arg1Val = cs.getArgument(1); IntervalValue strLen0 = AbstractInterpretation::getAEInstance().getStrlen(as, arg0Val); @@ -359,7 +359,7 @@ bool BufOverflowDetector::detectStrcat(AbstractState& as, const CallICFGNode *ca } else if (std::find(strncatGroup.begin(), strncatGroup.end(), fun->getName()) != strncatGroup.end()) { - CallSite cs = SVFUtil::getSVFCallSite(call->getCallSite()); + CallSite cs = SVFUtil::getSVFCallSite(call); const SVFValue* arg0Val = cs.getArgument(0); const SVFValue* arg2Val = cs.getArgument(2); IntervalValue arg2Num = as[svfir->getValueNode(arg2Val)].getInterval(); diff --git a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp index bcc3f8c8a..9b68be859 100644 --- a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp +++ b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp @@ -1359,7 +1359,7 @@ void AbstractInterpretation::handleExtAPI(const CallICFGNode *call) AbstractState& as = getAbsStateFromTrace(call); const SVFFunction *fun = SVFUtil::getCallee(call->getCallSite()); assert(fun && "SVFFunction* is nullptr"); - CallSite cs = SVFUtil::getSVFCallSite(call->getCallSite()); + CallSite cs = SVFUtil::getSVFCallSite(call); ExtAPIType extType = UNCLASSIFIED; // get type of mem api for (const std::string &annotation: fun->getAnnotations()) @@ -1381,7 +1381,7 @@ void AbstractInterpretation::handleExtAPI(const CallICFGNode *call) } else { - u32_t lhsId = svfir->getValueNode(SVFUtil::getSVFCallSite(call->getCallSite()).getInstruction()); + u32_t lhsId = svfir->getValueNode(SVFUtil::getSVFCallSite(call).getInstruction()); if (as.inVarToAddrsTable(lhsId)) { @@ -1463,7 +1463,7 @@ void AbstractInterpretation::handleStrcpy(const CallICFGNode *call) // strcpy, __strcpy_chk, stpcpy , wcscpy, __wcscpy_chk // get the dst and src AbstractState& as = getAbsStateFromTrace(call); - CallSite cs = SVFUtil::getSVFCallSite(call->getCallSite()); + CallSite cs = SVFUtil::getSVFCallSite(call); const SVFValue* arg0Val = cs.getArgument(0); const SVFValue* arg1Val = cs.getArgument(1); IntervalValue strLen = getStrlen(as, arg1Val); @@ -1553,12 +1553,12 @@ void AbstractInterpretation::handleStrcat(const SVF::CallICFGNode *call) // __strcat_chk, strcat, __wcscat_chk, wcscat, __strncat_chk, strncat, __wcsncat_chk, wcsncat // to check it is strcat group or strncat group AbstractState& as = getAbsStateFromTrace(call); - const SVFFunction *fun = SVFUtil::getCallee(call->getCallSite()); + const SVFFunction *fun = SVFUtil::getCallee(call); const std::vector strcatGroup = {"__strcat_chk", "strcat", "__wcscat_chk", "wcscat"}; const std::vector strncatGroup = {"__strncat_chk", "strncat", "__wcsncat_chk", "wcsncat"}; if (std::find(strcatGroup.begin(), strcatGroup.end(), fun->getName()) != strcatGroup.end()) { - CallSite cs = SVFUtil::getSVFCallSite(call->getCallSite()); + CallSite cs = SVFUtil::getSVFCallSite(call); const SVFValue* arg0Val = cs.getArgument(0); const SVFValue* arg1Val = cs.getArgument(1); IntervalValue strLen0 = getStrlen(as, arg0Val); @@ -1569,7 +1569,7 @@ void AbstractInterpretation::handleStrcat(const SVF::CallICFGNode *call) } else if (std::find(strncatGroup.begin(), strncatGroup.end(), fun->getName()) != strncatGroup.end()) { - CallSite cs = SVFUtil::getSVFCallSite(call->getCallSite()); + CallSite cs = SVFUtil::getSVFCallSite(call); const SVFValue* arg0Val = cs.getArgument(0); const SVFValue* arg1Val = cs.getArgument(1); const SVFValue* arg2Val = cs.getArgument(2); diff --git a/svf/lib/CFL/CFLAlias.cpp b/svf/lib/CFL/CFLAlias.cpp index 4a97ba8ff..ebc6bc27a 100644 --- a/svf/lib/CFL/CFLAlias.cpp +++ b/svf/lib/CFL/CFLAlias.cpp @@ -42,9 +42,9 @@ void CFLAlias::onTheFlyCallGraphSolve(const CallSiteToFunPtrMap& callsites, Call { const CallICFGNode* cs = iter->first; - if (SVFUtil::getSVFCallSite(cs->getCallSite()).isVirtualCall()) + if (SVFUtil::getSVFCallSite(cs).isVirtualCall()) { - const SVFValue* vtbl = SVFUtil::getSVFCallSite(cs->getCallSite()).getVtablePtr(); + const SVFValue* vtbl = SVFUtil::getSVFCallSite(cs).getVtablePtr(); assert(pag->hasValueNode(vtbl)); NodeID vtblId = pag->getValueNode(vtbl); resolveCPPIndCalls(cs, getCFLPts(vtblId), newEdges); @@ -175,7 +175,7 @@ bool CFLAlias::updateCallGraph(const CallSiteToFunPtrMap& callsites) onTheFlyCallGraphSolve(callsites,newEdges); for(CallEdgeMap::iterator it = newEdges.begin(), eit = newEdges.end(); it!=eit; ++it ) { - CallSite cs = SVFUtil::getSVFCallSite(it->first->getCallSite()); + CallSite cs = SVFUtil::getSVFCallSite(it->first); for(FunctionSet::iterator cit = it->second.begin(), ecit = it->second.end(); cit!=ecit; ++cit) { connectCaller2CalleeParams(cs,*cit); diff --git a/svf/lib/DDA/DDAClient.cpp b/svf/lib/DDA/DDAClient.cpp index cb3bd58d7..d10e38110 100644 --- a/svf/lib/DDA/DDAClient.cpp +++ b/svf/lib/DDA/DDAClient.cpp @@ -81,9 +81,9 @@ OrderedNodeSet& FunptrDDAClient::collectCandidateQueries(SVFIR* p) for(SVFIR::CallSiteToFunPtrMap::const_iterator it = pag->getIndirectCallsites().begin(), eit = pag->getIndirectCallsites().end(); it!=eit; ++it) { - if (SVFUtil::getSVFCallSite(it->first->getCallSite()).isVirtualCall()) + if (SVFUtil::getSVFCallSite(it->first).isVirtualCall()) { - const SVFValue* vtblPtr = SVFUtil::getSVFCallSite(it->first->getCallSite()).getVtablePtr(); + const SVFValue* vtblPtr = SVFUtil::getSVFCallSite(it->first).getVtablePtr(); assert(pag->hasValueNode(vtblPtr) && "not a vtable pointer?"); NodeID vtblId = pag->getValueNode(vtblPtr); addCandidate(vtblId); diff --git a/svf/lib/Graphs/CallGraph.cpp b/svf/lib/Graphs/CallGraph.cpp index cad7a8863..1f262c255 100644 --- a/svf/lib/Graphs/CallGraph.cpp +++ b/svf/lib/Graphs/CallGraph.cpp @@ -51,7 +51,7 @@ void CallGraphEdge::addDirectCallSite(const CallICFGNode* call) void CallGraphEdge::addInDirectCallSite(const CallICFGNode* call) { - assert((nullptr == SVFUtil::getCallee(call->getCallSite()) || nullptr == SVFUtil::dyn_cast (SVFUtil::getForkedFun(call->getCallSite()))) && "not an indirect callsite??"); + assert((nullptr == SVFUtil::getCallee(call->getCallSite()) || nullptr == SVFUtil::dyn_cast (SVFUtil::getForkedFun(call))) && "not an indirect callsite??"); indirectCalls.insert(call); } //@} diff --git a/svf/lib/Graphs/ThreadCallGraph.cpp b/svf/lib/Graphs/ThreadCallGraph.cpp index d2b2c2732..c04b90412 100644 --- a/svf/lib/Graphs/ThreadCallGraph.cpp +++ b/svf/lib/Graphs/ThreadCallGraph.cpp @@ -70,7 +70,7 @@ void ThreadCallGraph::updateCallGraph(PointerAnalysis* pta) // Fork sites for (CallSiteSet::const_iterator it = forksitesBegin(), eit = forksitesEnd(); it != eit; ++it) { - const SVFValue* forkedval = tdAPI->getForkedFun((*it)->getCallSite()); + const SVFValue* forkedval = tdAPI->getForkedFun(*it); if(SVFUtil::dyn_cast(forkedval)==nullptr) { SVFIR* pag = pta->getPAG(); @@ -105,7 +105,7 @@ void ThreadCallGraph::updateJoinEdge(PointerAnalysis* pta) CallSiteSet forkset; for (CallSiteSet::const_iterator it = forksitesBegin(), eit = forksitesEnd(); it != eit; ++it) { - const SVFValue* forkthread = tdAPI->getForkedThread((*it)->getCallSite()); + const SVFValue* forkthread = tdAPI->getForkedThread(*it); if (pta->alias(jointhread, forkthread)) { forkset.insert(*it); @@ -123,7 +123,7 @@ void ThreadCallGraph::addDirectForkEdge(const CallICFGNode* cs) { CallGraphNode* caller = getCallGraphNode(cs->getCaller()); - const SVFFunction* forkee = SVFUtil::dyn_cast(tdAPI->getForkedFun(cs->getCallSite())); + const SVFFunction* forkee = SVFUtil::dyn_cast(tdAPI->getForkedFun(cs)); assert(forkee && "callee does not exist"); CallGraphNode* callee = getCallGraphNode(forkee->getDefFunForMultipleModule()); CallSiteID csId = addCallSite(cs, callee->getFunction()); @@ -176,7 +176,7 @@ void ThreadCallGraph::addDirectJoinEdge(const CallICFGNode* cs,const CallSiteSet for (CallSiteSet::const_iterator it = forkset.begin(), eit = forkset.end(); it != eit; ++it) { - const SVFFunction* threadRoutineFun = SVFUtil::dyn_cast(tdAPI->getForkedFun((*it)->getCallSite())); + const SVFFunction* threadRoutineFun = SVFUtil::dyn_cast(tdAPI->getForkedFun(*it)); assert(threadRoutineFun && "thread routine function does not exist"); CallGraphNode* threadRoutineFunNode = getCallGraphNode(threadRoutineFun); CallSiteID csId = addCallSite(cs, threadRoutineFun); diff --git a/svf/lib/Graphs/VFG.cpp b/svf/lib/Graphs/VFG.cpp index 915d7df4f..0da066bbc 100644 --- a/svf/lib/Graphs/VFG.cpp +++ b/svf/lib/Graphs/VFG.cpp @@ -979,7 +979,7 @@ void VFG::connectCallerAndCallee(const CallICFGNode* callBlockNode, const SVFFun RetICFGNode* retBlockNode = icfg->getRetICFGNode(callBlockNode->getCallSite()); // connect actual and formal param if (pag->hasCallSiteArgsMap(callBlockNode) && pag->hasFunArgsList(callee) && - matchArgs(callBlockNode->getCallSite(), callee)) + matchArgs(callBlockNode, callee)) { const SVFIR::SVFVarList& csArgList = pag->getCallSiteArgsList(callBlockNode); const SVFIR::SVFVarList& funArgList = pag->getFunArgsList(callee); diff --git a/svf/lib/MTA/MTAStat.cpp b/svf/lib/MTA/MTAStat.cpp index 78ebb0075..463d7bacc 100644 --- a/svf/lib/MTA/MTAStat.cpp +++ b/svf/lib/MTA/MTAStat.cpp @@ -49,7 +49,7 @@ void MTAStat::performThreadCallGraphStat(ThreadCallGraph* tcg) for (ThreadCallGraph::CallSiteSet::const_iterator it = tcg->forksitesBegin(), eit = tcg->forksitesEnd(); it != eit; ++it) { bool indirectfork = false; - const SVFFunction* spawnee = SVFUtil::dyn_cast(tcg->getThreadAPI()->getForkedFun((*it)->getCallSite())); + const SVFFunction* spawnee = SVFUtil::dyn_cast(tcg->getThreadAPI()->getForkedFun(*it)); if(spawnee==nullptr) { numOfIndForksite++; diff --git a/svf/lib/MemoryModel/PointerAnalysis.cpp b/svf/lib/MemoryModel/PointerAnalysis.cpp index ad8fcf408..d8f0285e5 100644 --- a/svf/lib/MemoryModel/PointerAnalysis.cpp +++ b/svf/lib/MemoryModel/PointerAnalysis.cpp @@ -404,7 +404,7 @@ void PointerAnalysis::resolveIndCalls(const CallICFGNode* cs, const PointsTo& ta const SVFFunction* calleefun = SVFUtil::cast(obj->getValue()); const SVFFunction* callee = calleefun->getDefFunForMultipleModule(); - if(SVFUtil::matchArgs(cs->getCallSite(), callee) == false) + if(SVFUtil::matchArgs(cs, callee) == false) continue; if(0 == getIndCallMap()[cs].count(callee)) @@ -428,8 +428,8 @@ void PointerAnalysis::resolveIndCalls(const CallICFGNode* cs, const PointsTo& ta */ void PointerAnalysis::getVFnsFromCHA(const CallICFGNode* cs, VFunSet &vfns) { - if (chgraph->csHasVFnsBasedonCHA(SVFUtil::getSVFCallSite(cs->getCallSite()))) - vfns = chgraph->getCSVFsBasedonCHA(SVFUtil::getSVFCallSite(cs->getCallSite())); + if (chgraph->csHasVFnsBasedonCHA(SVFUtil::getSVFCallSite(cs))) + vfns = chgraph->getCSVFsBasedonCHA(SVFUtil::getSVFCallSite(cs)); } /* @@ -438,10 +438,10 @@ void PointerAnalysis::getVFnsFromCHA(const CallICFGNode* cs, VFunSet &vfns) void PointerAnalysis::getVFnsFromPts(const CallICFGNode* cs, const PointsTo &target, VFunSet &vfns) { - if (chgraph->csHasVtblsBasedonCHA(SVFUtil::getSVFCallSite(cs->getCallSite()))) + if (chgraph->csHasVtblsBasedonCHA(SVFUtil::getSVFCallSite(cs))) { Set vtbls; - const VTableSet &chaVtbls = chgraph->getCSVtblsBasedonCHA(SVFUtil::getSVFCallSite(cs->getCallSite())); + const VTableSet &chaVtbls = chgraph->getCSVtblsBasedonCHA(SVFUtil::getSVFCallSite(cs)); for (PointsTo::iterator it = target.begin(), eit = target.end(); it != eit; ++it) { const PAGNode *ptdnode = pag->getGNode(*it); @@ -454,7 +454,7 @@ void PointerAnalysis::getVFnsFromPts(const CallICFGNode* cs, const PointsTo &tar } } } - chgraph->getVFnsFromVtbls(SVFUtil::getSVFCallSite(cs->getCallSite()), vtbls, vfns); + chgraph->getVFnsFromVtbls(SVFUtil::getSVFCallSite(cs), vtbls, vfns); } } @@ -471,8 +471,8 @@ void PointerAnalysis::connectVCallToVFns(const CallICFGNode* cs, const VFunSet & callee = callee->getDefFunForMultipleModule(); if (getIndCallMap()[cs].count(callee) > 0) continue; - if(SVFUtil::getSVFCallSite(cs->getCallSite()).arg_size() == callee->arg_size() || - (SVFUtil::getSVFCallSite(cs->getCallSite()).isVarArg() && callee->isVarArg())) + if(SVFUtil::getSVFCallSite(cs).arg_size() == callee->arg_size() || + (SVFUtil::getSVFCallSite(cs).isVarArg() && callee->isVarArg())) { newEdges[cs].insert(callee); getIndCallMap()[cs].insert(callee); @@ -485,7 +485,7 @@ void PointerAnalysis::connectVCallToVFns(const CallICFGNode* cs, const VFunSet & /// Resolve cpp indirect call edges void PointerAnalysis::resolveCPPIndCalls(const CallICFGNode* cs, const PointsTo& target, CallEdgeMap& newEdges) { - assert(SVFUtil::getSVFCallSite(cs->getCallSite()).isVirtualCall() && "not cpp virtual call"); + assert(SVFUtil::getSVFCallSite(cs).isVirtualCall() && "not cpp virtual call"); VFunSet vfns; if (Options::ConnectVCallOnCHA()) diff --git a/svf/lib/MemoryModel/PointerAnalysisImpl.cpp b/svf/lib/MemoryModel/PointerAnalysisImpl.cpp index de0ccd365..d12b79e91 100644 --- a/svf/lib/MemoryModel/PointerAnalysisImpl.cpp +++ b/svf/lib/MemoryModel/PointerAnalysisImpl.cpp @@ -495,9 +495,9 @@ void BVDataPTAImpl::onTheFlyCallGraphSolve(const CallSiteToFunPtrMap& callsites, { const CallICFGNode* cs = iter->first; - if (SVFUtil::getSVFCallSite(cs->getCallSite()).isVirtualCall()) + if (SVFUtil::getSVFCallSite(cs).isVirtualCall()) { - const SVFValue* vtbl = SVFUtil::getSVFCallSite(cs->getCallSite()).getVtablePtr(); + const SVFValue* vtbl = SVFUtil::getSVFCallSite(cs).getVtablePtr(); assert(pag->hasValueNode(vtbl)); NodeID vtblId = pag->getValueNode(vtbl); resolveCPPIndCalls(cs, getPts(vtblId), newEdges); diff --git a/svf/lib/Util/CallGraphBuilder.cpp b/svf/lib/Util/CallGraphBuilder.cpp index bcde14a63..245bff7cc 100644 --- a/svf/lib/Util/CallGraphBuilder.cpp +++ b/svf/lib/Util/CallGraphBuilder.cpp @@ -84,7 +84,7 @@ CallGraph* ThreadCallGraphBuilder::buildThreadCallGraph(SVFModule* svfModule) { const CallICFGNode* cs = cast(inst); cg->addForksite(cs); - const SVFFunction* forkee = SVFUtil::dyn_cast(tdAPI->getForkedFun(inst)); + const SVFFunction* forkee = SVFUtil::dyn_cast(tdAPI->getForkedFun(cs)); if (forkee) { cg->addDirectForkEdge(cs); diff --git a/svf/lib/Util/SVFUtil.cpp b/svf/lib/Util/SVFUtil.cpp index a9c954786..65a4d1487 100644 --- a/svf/lib/Util/SVFUtil.cpp +++ b/svf/lib/Util/SVFUtil.cpp @@ -317,9 +317,10 @@ void SVFUtil::stopAnalysisLimitTimer(bool limitTimerSet) /// unless the callee is a variadic function (the first parameter of variadic function is its parameter number) /// e.g., void variadicFoo(int num, ...); variadicFoo(5, 1,2,3,4,5) /// for variadic function, callsite arg size must be greater than or equal to callee arg size -bool SVFUtil::matchArgs(const CallSite cs, const SVFFunction* callee) +bool SVFUtil::matchArgs(const CallICFGNode* call, const SVFFunction* callee) { - if (callee->isVarArg() || ThreadAPI::getThreadAPI()->isTDFork(cs.getInstruction())) + CallSite cs(call->getCallSite()); + if (callee->isVarArg() || ThreadAPI::getThreadAPI()->isTDFork(call)) return cs.arg_size() >= callee->arg_size(); else return cs.arg_size() == callee->arg_size(); diff --git a/svf/lib/Util/ThreadAPI.cpp b/svf/lib/Util/ThreadAPI.cpp index 569350898..e2399d9c9 100644 --- a/svf/lib/Util/ThreadAPI.cpp +++ b/svf/lib/Util/ThreadAPI.cpp @@ -140,15 +140,6 @@ const SVFFunction* ThreadAPI::getCallee(const ICFGNode *inst) const return nullptr; } -/*! - * - */ -const SVFFunction* ThreadAPI::getCallee(const SVFInstruction *inst) const -{ - return SVFUtil::getCallee(inst); -} - - const CallSite ThreadAPI::getSVFCallSite(const ICFGNode *inst) const { assert(SVFUtil::isa(inst) && "not a callsite?"); @@ -160,19 +151,11 @@ const SVFValue* ThreadAPI::getLockVal(const ICFGNode *inst) const { const CallICFGNode* call = SVFUtil::dyn_cast(inst); assert(call && "not a call ICFGNode?"); - assert((isTDAcquire(call->getCallSite()) || isTDRelease(call->getCallSite())) && "not a lock acquire or release function"); - CallSite cs = getSVFCallSite(call->getCallSite()); + assert((isTDAcquire(call) || isTDRelease(call)) && "not a lock acquire or release function"); + CallSite cs = getSVFCallSite(call); return cs.getArgument(0); } -/*! - * - */ -const CallSite ThreadAPI::getSVFCallSite(const SVFInstruction *inst) const -{ - return SVFUtil::getSVFCallSite(inst); -} - const SVFValue* ThreadAPI::getJoinedThread(const ICFGNode *inst) const { assert(isTDJoin(inst) && "not a thread join function!"); diff --git a/svf/lib/WPA/Andersen.cpp b/svf/lib/WPA/Andersen.cpp index e054f5d99..a410577aa 100644 --- a/svf/lib/WPA/Andersen.cpp +++ b/svf/lib/WPA/Andersen.cpp @@ -661,7 +661,7 @@ bool Andersen::updateCallGraph(const CallSiteToFunPtrMap& callsites) NodePairSet cpySrcNodes; /// nodes as a src of a generated new copy edge for(CallEdgeMap::iterator it = newEdges.begin(), eit = newEdges.end(); it!=eit; ++it ) { - CallSite cs = SVFUtil::getSVFCallSite(it->first->getCallSite()); + CallSite cs = SVFUtil::getSVFCallSite(it->first); for(FunctionSet::iterator cit = it->second.begin(), ecit = it->second.end(); cit!=ecit; ++cit) { connectCaller2CalleeParams(cs,*cit,cpySrcNodes); diff --git a/svf/lib/WPA/AndersenSCD.cpp b/svf/lib/WPA/AndersenSCD.cpp index e3a14e9c8..7e0091a4e 100644 --- a/svf/lib/WPA/AndersenSCD.cpp +++ b/svf/lib/WPA/AndersenSCD.cpp @@ -281,7 +281,7 @@ bool AndersenSCD::updateCallGraph(const PointerAnalysis::CallSiteToFunPtrMap& ca NodePairSet cpySrcNodes; /// nodes as a src of a generated new copy edge for(CallEdgeMap::iterator it = newEdges.begin(), eit = newEdges.end(); it!=eit; ++it ) { - CallSite cs = SVFUtil::getSVFCallSite(it->first->getCallSite()); + CallSite cs = SVFUtil::getSVFCallSite(it->first); for(FunctionSet::iterator cit = it->second.begin(), ecit = it->second.end(); cit!=ecit; ++cit) { connectCaller2CalleeParams(cs,*cit,cpySrcNodes); diff --git a/svf/lib/WPA/Steensgaard.cpp b/svf/lib/WPA/Steensgaard.cpp index fd4d4336f..ebd1f769d 100644 --- a/svf/lib/WPA/Steensgaard.cpp +++ b/svf/lib/WPA/Steensgaard.cpp @@ -135,7 +135,7 @@ bool Steensgaard::updateCallGraph(const CallSiteToFunPtrMap& callsites) for (CallEdgeMap::iterator it = newEdges.begin(), eit = newEdges.end(); it != eit; ++it) { - CallSite cs = SVFUtil::getSVFCallSite(it->first->getCallSite()); + CallSite cs = SVFUtil::getSVFCallSite(it->first); for (FunctionSet::iterator cit = it->second.begin(), ecit = it->second.end(); cit != ecit; ++cit) diff --git a/svf/lib/WPA/TypeAnalysis.cpp b/svf/lib/WPA/TypeAnalysis.cpp index e19235164..ed3746618 100644 --- a/svf/lib/WPA/TypeAnalysis.cpp +++ b/svf/lib/WPA/TypeAnalysis.cpp @@ -77,7 +77,7 @@ void TypeAnalysis::callGraphSolveBasedOnCHA(const CallSiteToFunPtrMap& callsites for(CallSiteToFunPtrMap::const_iterator iter = callsites.begin(), eiter = callsites.end(); iter!=eiter; ++iter) { const CallICFGNode* cbn = iter->first; - CallSite cs = SVFUtil::getSVFCallSite(cbn->getCallSite()); + CallSite cs = SVFUtil::getSVFCallSite(cbn); if (cs.isVirtualCall()) { const SVFValue* vtbl = cs.getVtablePtr();