Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge the isStrongUpdate in to SVFUtil #1280

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 19 additions & 0 deletions svf/lib/Util/SVFUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,22 @@ bool SVFUtil::matchArgs(const SVFInstruction* cs, const SVFFunction* callee)
else
return getSVFCallSite(cs).arg_size() == callee->arg_size();
}

bool SVFUtil::isStrongUpdate(const PointsTo &dstCPSet, NodeID &singleton, BVDataPTAImpl *pta) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this method in pointeranalysis class and rename it to be ‘isSingleton’ with only one argument pts

bool isSU = false;

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;
}
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
Loading