Skip to content

Commit

Permalink
Merge pull request #1532 from yuleisui/master
Browse files Browse the repository at this point in the history
Refactoring SVFInstruction: stage 6
  • Loading branch information
yuleisui authored Aug 26, 2024
2 parents 21eb667 + f976126 commit e8df0a9
Show file tree
Hide file tree
Showing 21 changed files with 84 additions and 75 deletions.
14 changes: 1 addition & 13 deletions svf/include/AE/Svfexe/AEDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,21 +218,9 @@ class BufOverflowDetector : public AEDetector
*/
void addBugToReporter(const AEException& e, const ICFGNode* node)
{
const SVFInstruction* inst = nullptr;

// Determine the instruction associated with the ICFG node
if (const CallICFGNode* call = SVFUtil::dyn_cast<CallICFGNode>(node))
{
inst = call->getCallSite(); // If the node is a call node, get the call site instruction
}
else
{
inst = node->getSVFStmts().back()->getInst(); // Otherwise, get the last instruction of the node's
// statements
}

GenericBug::EventStack eventStack;
SVFBugEvent sourceInstEvent(SVFBugEvent::EventType::SourceInst, inst);
SVFBugEvent sourceInstEvent(SVFBugEvent::EventType::SourceInst, node);
eventStack.push_back(sourceInstEvent); // Add the source instruction event to the event stack

if (eventStack.empty())
Expand Down
33 changes: 33 additions & 0 deletions svf/include/Graphs/ICFGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ class ICFGNode : public GenericICFGNodeTy

virtual const std::string toString() const;

virtual const std::string getSourceLoc() const = 0;

void dump() const;

protected:
Expand Down Expand Up @@ -172,6 +174,11 @@ class GlobalICFGNode : public ICFGNode
//@}

virtual const std::string toString() const;

virtual const std::string getSourceLoc() const
{
return "Global ICFGNode";
}
};

/*!
Expand Down Expand Up @@ -218,6 +225,11 @@ class IntraICFGNode : public ICFGNode
//@}

const std::string toString() const;

virtual const std::string getSourceLoc() const
{
return inst->getSourceLoc();
}
};

class InterICFGNode : public ICFGNode
Expand Down Expand Up @@ -252,6 +264,7 @@ class InterICFGNode : public ICFGNode
|| node->getNodeKind() == FunRetBlock;
}
//@}
virtual const std::string getSourceLoc() const = 0;
};


Expand Down Expand Up @@ -316,6 +329,11 @@ class FunEntryICFGNode : public InterICFGNode
//@}

const virtual std::string toString() const;

virtual const std::string getSourceLoc() const
{
return "function entry: " + fun->getSourceLoc();
}
};

/*!
Expand Down Expand Up @@ -377,6 +395,11 @@ class FunExitICFGNode : public InterICFGNode
//@}

virtual const std::string toString() const;

virtual const std::string getSourceLoc() const
{
return "function ret: " + fun->getSourceLoc();
}
};

/*!
Expand Down Expand Up @@ -478,6 +501,11 @@ class CallICFGNode : public InterICFGNode
//@}

virtual const std::string toString() const;

virtual const std::string getSourceLoc() const
{
return "CallICFGNode: " + cs->getSourceLoc();
}
};


Expand Down Expand Up @@ -554,6 +582,11 @@ class RetICFGNode : public InterICFGNode
//@}

virtual const std::string toString() const;

virtual const std::string getSourceLoc() const
{
return "RetICFGNode: " + cs->getSourceLoc();
}
};

} // End namespace SVF
Expand Down
6 changes: 0 additions & 6 deletions svf/include/Graphs/VFGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,6 @@ class StmtVFGNode : public VFGNode
|| node->getNodeKind() == Store
|| node->getNodeKind() == Load;
}

inline const SVFInstruction* getInst() const
{
/// should return a valid instruction unless it is a global PAGEdge
return pagEdge->getInst();
}
//@}

const SVFValue* getValue() const override;
Expand Down
2 changes: 1 addition & 1 deletion svf/include/MTA/LockAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class LockAnalysis
void handleIntra(const CxtStmt& cts);

/// Handle call relations
void handleCallRelation(CxtLockProc& clp, const CallGraphEdge* cgEdge, CallSite call);
void handleCallRelation(CxtLockProc& clp, const CallGraphEdge* cgEdge, const CallICFGNode* call);

/// Return true it a lock matches an unlock
bool isAliasedLocks(const CxtLock& cl1, const CxtLock& cl2)
Expand Down
11 changes: 1 addition & 10 deletions svf/include/MTA/TCT.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,6 @@ class TCT: public GenericThreadCreateTreeTy
{
destroy();
}
/// Get CallICFGNode given inst
CallICFGNode* getCallICFGNode(const SVFInstruction* inst)
{
return pta->getICFG()->getCallICFGNode(inst);
}
const ICFGNode* getICFGNode(const SVFInstruction* inst)
{
return pta->getICFG()->getICFGNode(inst);
}

/// Get SVFFModule
SVFModule* getSVFModule() const
Expand Down Expand Up @@ -497,7 +488,7 @@ class TCT: public GenericThreadCreateTreeTy
//@}

/// Handle call relations
void handleCallRelation(CxtThreadProc& ctp, const CallGraphEdge* cgEdge, CallSite call);
void handleCallRelation(CxtThreadProc& ctp, const CallGraphEdge* cgEdge, const CallICFGNode* call);

/// Get or create a tct node based on CxtThread
//@{
Expand Down
10 changes: 5 additions & 5 deletions svf/include/SABER/SaberCondAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SaberCondAllocator
public:

typedef Z3Expr Condition; /// z3 condition
typedef Map<u32_t, const SVFInstruction *> IndexToTermInstMap; /// id to instruction map for z3
typedef Map<u32_t, const ICFGNode*> IndexToTermInstMap; /// id to instruction map for z3
typedef Map<u32_t,Condition> CondPosMap; ///< map a branch to its Condition
typedef Map<const SVFBasicBlock*, CondPosMap > BBCondMap; /// map bb to a Condition
typedef Set<const SVFBasicBlock*> BasicBlockSet;
Expand Down Expand Up @@ -118,21 +118,21 @@ class SaberCondAllocator
}

/// Allocate a new condition
Condition newCond(const SVFInstruction* inst);
Condition newCond(const ICFGNode* inst);

/// Perform path allocation
void allocate(const SVFModule* module);

/// Get/Set instruction based on Z3 expression id
//{@
inline const SVFInstruction* getCondInst(u32_t id) const
inline const ICFGNode* getCondInst(u32_t id) const
{
IndexToTermInstMap::const_iterator it = idToTermInstMap.find(id);
assert(it != idToTermInstMap.end() && "this should be a fresh condition");
return it->second;
}

inline void setCondInst(const Condition &condition, const SVFInstruction* inst)
inline void setCondInst(const Condition &condition, const ICFGNode* inst)
{
assert(idToTermInstMap.find(condition.id()) == idToTermInstMap.end() && "this should be a fresh condition");
idToTermInstMap[condition.id()] = inst;
Expand Down Expand Up @@ -235,7 +235,7 @@ class SaberCondAllocator


/// mark neg Z3 expression
inline void setNegCondInst(const Condition &condition, const SVFInstruction* inst)
inline void setNegCondInst(const Condition &condition, const ICFGNode* inst)
{
setCondInst(condition, inst);
negConds.set(condition.id());
Expand Down
4 changes: 2 additions & 2 deletions svf/include/Util/SVFBugReport.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ class SVFBugEvent

protected:
u32_t typeAndInfoFlag;
const SVFInstruction *eventInst;
const ICFGNode *eventInst;

public:
SVFBugEvent(u32_t typeAndInfoFlag, const SVFInstruction *eventInst): typeAndInfoFlag(typeAndInfoFlag), eventInst(eventInst) { };
SVFBugEvent(u32_t typeAndInfoFlag, const ICFGNode *eventInst): typeAndInfoFlag(typeAndInfoFlag), eventInst(eventInst) { };
virtual ~SVFBugEvent() = default;

inline u32_t getEventType() const
Expand Down
7 changes: 6 additions & 1 deletion svf/include/Util/SVFUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,12 @@ inline bool isNonInstricCallSite(const ICFGNode* inst)
return isCallSite(inst);
}

/// Return LLVM callsite given an instruction


/// 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?");
Expand Down
6 changes: 2 additions & 4 deletions svf/lib/Graphs/IRGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,11 @@ struct DOTGraphTraits<IRGraph*> : public DefaultDOTGraphTraits
assert(edge && "No edge found!!");
if(const CallPE* calledge = SVFUtil::dyn_cast<CallPE>(edge))
{
const SVFInstruction* callInst= calledge->getCallSite()->getCallSite();
return callInst->getSourceLoc();
return calledge->getCallSite()->getSourceLoc();
}
else if(const RetPE* retedge = SVFUtil::dyn_cast<RetPE>(edge))
{
const SVFInstruction* callInst= retedge->getCallSite()->getCallSite();
return callInst->getSourceLoc();
return retedge->getCallSite()->getSourceLoc();
}
return "";
}
Expand Down
8 changes: 4 additions & 4 deletions svf/lib/MTA/LockAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ void LockAnalysis::collectCxtLock()
DBOUT(DMTA,
outs() << "\nCollecting CxtLocks: handling direct call:" << **cit << "\t" << cgEdge->getSrcNode()->getFunction()->getName()
<< "-->" << cgEdge->getDstNode()->getFunction()->getName() << "\n");
handleCallRelation(clp, cgEdge, getSVFCallSite((*cit)->getCallSite()));
handleCallRelation(clp, cgEdge, *cit);
}
for (CallGraphEdge::CallInstSet::const_iterator ind = cgEdge->indirectCallsBegin(), eind = cgEdge->indirectCallsEnd();
ind != eind; ++ind)
Expand All @@ -295,7 +295,7 @@ void LockAnalysis::collectCxtLock()
outs() << "\nCollecting CxtLocks: handling indirect call:" << **ind << "\t"
<< cgEdge->getSrcNode()->getFunction()->getName() << "-->" << cgEdge->getDstNode()->getFunction()->getName()
<< "\n");
handleCallRelation(clp, cgEdge, getSVFCallSite((*ind)->getCallSite()));
handleCallRelation(clp, cgEdge, *ind);
}
}
}
Expand All @@ -305,11 +305,11 @@ void LockAnalysis::collectCxtLock()
/*!
* Handling call relations when collecting context-sensitive locks
*/
void LockAnalysis::handleCallRelation(CxtLockProc& clp, const CallGraphEdge* cgEdge, CallSite cs)
void LockAnalysis::handleCallRelation(CxtLockProc& clp, const CallGraphEdge* cgEdge, const CallICFGNode* cs)
{

CallStrCxt cxt(clp.getContext());
const ICFGNode* curNode = tct->getICFGNode(cs.getInstruction());
const ICFGNode* curNode = cs;
if (isTDAcquire(curNode))
{
addCxtLock(cxt,curNode);
Expand Down
4 changes: 2 additions & 2 deletions svf/lib/MTA/MHP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ void ForkJoinAnalysis::handleRet(const CxtStmt& cts)
cit != ecit; ++cit)
{
CallStrCxt newCxt = curCxt;
const ICFGNode* curNode = tct->getICFGNode((*cit)->getCallSite());
const ICFGNode* curNode = (*cit);
if (matchCxt(newCxt, SVFUtil::cast<CallICFGNode>(curNode), curFunNode->getFunction()))
{
for(const ICFGEdge* outEdge : curNode->getOutEdges())
Expand All @@ -930,7 +930,7 @@ void ForkJoinAnalysis::handleRet(const CxtStmt& cts)
cit != ecit; ++cit)
{
CallStrCxt newCxt = curCxt;
const ICFGNode* curNode = tct->getICFGNode((*cit)->getCallSite());
const ICFGNode* curNode = (*cit);

if (matchCxt(newCxt, SVFUtil::cast<CallICFGNode>(curNode), curFunNode->getFunction()))
{
Expand Down
1 change: 0 additions & 1 deletion svf/lib/MTA/MTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ void MTA::detect(SVFModule* module)
SVFIR* pag = SVFIR::getPAG();
PointerAnalysis* pta = AndersenWaveDiff::createAndersenWaveDiff(pag);

Set<const SVFInstruction*> needcheckinst;
// Add symbols for all of the functions and the instructions in them.
for (const SVFFunction* F : module->getFunctionSet())
{
Expand Down
8 changes: 4 additions & 4 deletions svf/lib/MTA/TCT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ void TCT::collectMultiForkedThreads()
/*!
* Handle call relations
*/
void TCT::handleCallRelation(CxtThreadProc& ctp, const CallGraphEdge* cgEdge, CallSite cs)
void TCT::handleCallRelation(CxtThreadProc& ctp, const CallGraphEdge* cgEdge, const CallICFGNode* cs)
{
const SVFFunction* callee = cgEdge->getDstNode()->getFunction();

CallStrCxt cxt(ctp.getContext());
CallStrCxt oldCxt = cxt;
const CallICFGNode* callNode = SVFUtil::cast<CallICFGNode>(getICFGNode(cs.getInstruction()));
const CallICFGNode* callNode = cs;
pushCxt(cxt,callNode,callee);

if(cgEdge->getEdgeKind() == CallGraphEdge::CallRetEdge)
Expand Down Expand Up @@ -416,13 +416,13 @@ void TCT::build()
ecit = cgEdge->directCallsEnd(); cit!=ecit; ++cit)
{
DBOUT(DMTA,outs() << "\nTCT handling direct call:" << **cit << "\t" << cgEdge->getSrcNode()->getFunction()->getName() << "-->" << cgEdge->getDstNode()->getFunction()->getName() << "\n");
handleCallRelation(ctp,cgEdge,getSVFCallSite((*cit)->getCallSite()));
handleCallRelation(ctp,cgEdge,*cit);
}
for(CallGraphEdge::CallInstSet::const_iterator ind = cgEdge->indirectCallsBegin(),
eind = cgEdge->indirectCallsEnd(); ind!=eind; ++ind)
{
DBOUT(DMTA,outs() << "\nTCT handling indirect call:" << **ind << "\t" << cgEdge->getSrcNode()->getFunction()->getName() << "-->" << cgEdge->getDstNode()->getFunction()->getName() << "\n");
handleCallRelation(ctp,cgEdge,getSVFCallSite((*ind)->getCallSite()));
handleCallRelation(ctp,cgEdge,*ind);
}
}
}
Expand Down
15 changes: 6 additions & 9 deletions svf/lib/MemoryModel/PointerAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,9 @@ void PointerAnalysis::validateSuccessTests(std::string fun)

for(const CallICFGNode* callNode : pag->getCallSiteSet())
{
const SVFInstruction* svfInst = callNode->getCallSite();
if (SVFUtil::getCallee(svfInst) == checkFun)
if (SVFUtil::getCallee(callNode) == checkFun)
{

CallSite cs(svfInst);
CallSite cs = SVFUtil::getSVFCallSite(callNode);
assert(cs.getNumArgOperands() == 2
&& "arguments should be two pointers!!");
const SVFValue* V1 = cs.getArgOperand(0);
Expand Down Expand Up @@ -551,12 +549,12 @@ void PointerAnalysis::validateSuccessTests(std::string fun)

if (checkSuccessful)
outs() << sucMsg("\t SUCCESS :") << fun << " check <id:" << id1 << ", id:" << id2 << "> at ("
<< svfInst->getSourceLoc() << ")\n";
<< callNode->getSourceLoc() << ")\n";
else
{
SVFUtil::errs() << errMsg("\t FAILURE :") << fun
<< " check <id:" << id1 << ", id:" << id2
<< "> at (" << svfInst->getSourceLoc() << ")\n";
<< "> at (" << callNode->getSourceLoc() << ")\n";
assert(false && "test case failed!");
}
}
Expand All @@ -577,10 +575,9 @@ void PointerAnalysis::validateExpectedFailureTests(std::string fun)

for(const CallICFGNode* callNode : pag->getCallSiteSet())
{
const SVFInstruction* svfInst = callNode->getCallSite();
if (SVFUtil::getCallee(svfInst) == checkFun)
if (SVFUtil::getCallee(callNode) == checkFun)
{
CallSite call = getSVFCallSite(svfInst);
CallSite call = getSVFCallSite(callNode);
assert(call.arg_size() == 2
&& "arguments should be two pointers!!");
const SVFValue* V1 = call.getArgOperand(0);
Expand Down
2 changes: 1 addition & 1 deletion svf/lib/SABER/DoubleFreeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void DoubleFreeChecker::reportBug(ProgSlice* slice)
GenericBug::EventStack eventStack;
slice->evalFinalCond2Event(eventStack);
eventStack.push_back(
SVFBugEvent(SVFBugEvent::SourceInst, getSrcCSID(slice->getSource())->getCallSite()));
SVFBugEvent(SVFBugEvent::SourceInst, getSrcCSID(slice->getSource())));
report.addSaberBug(GenericBug::DOUBLEFREE, eventStack);
}
if(Options::ValidateTests())
Expand Down
Loading

0 comments on commit e8df0a9

Please sign in to comment.