Skip to content

Commit

Permalink
merge the isStrongUpdate in to SVFUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
jumormt committed Dec 12, 2023
1 parent 1b74d0a commit c847eb5
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 62 deletions.
3 changes: 0 additions & 3 deletions svf/include/SABER/SaberSVFGBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ class SaberSVFGBuilder : public SVFGBuilder
/// Re-write create SVFG method
virtual void buildSVFG();

/// Return TRUE if this is a strong update STORE statement.
bool isStrongUpdate(const SVFGNode* node, NodeID& singleton, BVDataPTAImpl* pta);

private:
/// Remove direct value-flow edge to a dereference point for Saber source-sink memory error detection
/// for example, given two statements: p = alloc; q = *p, the direct SVFG edge between them is deleted
Expand Down
2 changes: 2 additions & 0 deletions svf/include/Util/SVFUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,8 @@ template <typename... Ts>
constexpr bool is_sequence_container_v = is_sequence_container<Ts...>::value;
///@}

/// Return true if a strong update can apply
bool isStrongUpdate(const PointsTo& dstCPSet, NodeID& singleton, BVDataPTAImpl* pta);

} // End namespace SVFUtil

Expand Down
2 changes: 0 additions & 2 deletions svf/include/WPA/FlowSensitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,6 @@ class FlowSensitive : public WPASVFGFSSolver, public BVDataPTAImpl
virtual void updateConnectedNodes(const SVFGEdgeSetTy& edges);
//@}

/// Return TRUE if this is a strong update STORE statement.
bool isStrongUpdate(const SVFGNode* node, NodeID& singleton);

/// Fills may/noAliases for the location/pointer pairs in cmp.
virtual void countAliases(Set<std::pair<NodeID, NodeID>> cmp, unsigned *mayAliases, unsigned *noAliases);
Expand Down
30 changes: 2 additions & 28 deletions svf/lib/SABER/SaberSVFGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,33 +215,6 @@ void SaberSVFGBuilder::rmDerefDirSVFGEdges(BVDataPTAImpl* pta)
}
}

/*!
* Return TRUE if this is a strong update STORE statement.
*/
bool SaberSVFGBuilder::isStrongUpdate(const SVFGNode* node, NodeID& singleton, BVDataPTAImpl* pta)
{
bool isSU = false;
if (const StoreSVFGNode* store = SVFUtil::dyn_cast<StoreSVFGNode>(node))
{
const PointsTo& dstCPSet = pta->getPts(store->getPAGDstNodeID());
if (dstCPSet.count() == 1)
{
/// Find the unique element in cpts
PointsTo::iterator it = dstCPSet.begin();
singleton = *it;

// Strong update can be made if this points-to target is not heap, array or field-insensitive.
if (!pta->isHeapMemObj(singleton) && !pta->isArrayMemObj(singleton)
&& SVFIR::getPAG()->getBaseObj(singleton)->isFieldInsensitive() == false
&& !pta->isLocalVarInRecursiveFun(singleton))
{
isSU = true;
}
}
}
return isSU;
}

/*!
* Remove Incoming Edge for strong-update (SU) store instruction
* Because the SU node does not receive indirect value
Expand All @@ -264,7 +237,8 @@ void SaberSVFGBuilder::rmIncomingEdgeForSUStore(BVDataPTAImpl* pta)
if(SVFUtil::isa<StoreStmt>(stmtNode->getPAGEdge()))
{
NodeID singleton;
if(isStrongUpdate(node, singleton, pta))
const PointsTo& dstCPSet = pta->getPts(stmtNode->getPAGDstNodeID());
if(SVFUtil::isStrongUpdate(dstCPSet, singleton, pta))
{
Set<SVFGEdge*> toRemove;
for (SVFGNode::const_iterator it2 = node->InEdgeBegin(), eit2 = node->InEdgeEnd(); it2 != eit2; ++it2)
Expand Down
30 changes: 2 additions & 28 deletions svf/lib/WPA/FlowSensitive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,8 @@ bool FlowSensitive::processStore(const StoreSVFGNode* store)
// also merge the DFInSet to DFOutSet.
/// check if this is a strong updates store
NodeID singleton;
bool isSU = isStrongUpdate(store, singleton);
const PointsTo &dstCPSet = getPts(store->getPAGDstNodeID());
bool isSU = SVFUtil::isStrongUpdate(dstCPSet, singleton, this);
if (isSU)
{
svfgHasSU.set(store->getId());
Expand All @@ -649,33 +650,6 @@ bool FlowSensitive::processStore(const StoreSVFGNode* store)
return changed;
}

/*!
* Return TRUE if this is a strong update STORE statement.
*/
bool FlowSensitive::isStrongUpdate(const SVFGNode* node, NodeID& singleton)
{
bool isSU = false;
if (const StoreSVFGNode* store = SVFUtil::dyn_cast<StoreSVFGNode>(node))
{
const PointsTo& dstCPSet = getPts(store->getPAGDstNodeID());
if (dstCPSet.count() == 1)
{
/// Find the unique element in cpts
PointsTo::iterator it = dstCPSet.begin();
singleton = *it;

// Strong update can be made if this points-to target is not heap, array or field-insensitive.
if (!isHeapMemObj(singleton) && !isArrayMemObj(singleton)
&& pag->getBaseObj(singleton)->isFieldInsensitive() == false
&& !isLocalVarInRecursiveFun(singleton))
{
isSU = true;
}
}
}
return isSU;
}

/*!
* Update call graph
*/
Expand Down
3 changes: 2 additions & 1 deletion svf/lib/WPA/VersionedFlowSensitive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,8 @@ bool VersionedFlowSensitive::processStore(const StoreSVFGNode* store)
double updateStart = stat->getClk();

NodeID singleton = 0;
bool isSU = isStrongUpdate(store, singleton);
const PointsTo &dstCPSet = getPts(store->getPAGDstNodeID());
bool isSU = SVFUtil::isStrongUpdate(dstCPSet, singleton, this);
if (isSU) svfgHasSU.set(l);
else svfgHasSU.reset(l);

Expand Down

0 comments on commit c847eb5

Please sign in to comment.