Skip to content

Commit

Permalink
Merge pull request #1315 from yuleisui/master
Browse files Browse the repository at this point in the history
remove isNonPointerObj API
  • Loading branch information
yuleisui authored Jan 4, 2024
2 parents bb344c0 + 4163e32 commit 882bb47
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 129 deletions.
24 changes: 15 additions & 9 deletions svf/include/DDA/DDAVFSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,23 @@ class DDAVFSolver
backtraceAlongDirectVF(gepPts,dpm);
unionDDAPts(pts, processGepPts(SVFUtil::cast<GepSVFGNode>(node),gepPts));
}
else if(SVFUtil::isa<LoadSVFGNode>(node))
else if(const LoadSVFGNode* load = SVFUtil::dyn_cast<LoadSVFGNode>(node))
{
if(load->getPAGDstNode()->isPointer() == false)
return;

CPtSet loadpts;
startNewPTCompFromLoadSrc(loadpts,dpm);
for(typename CPtSet::iterator it = loadpts.begin(), eit = loadpts.end(); it!=eit; ++it)
{
backtraceAlongIndirectVF(pts,getDPImWithOldCond(dpm,*it,node));
backtraceAlongIndirectVF(pts,getDPImWithOldCond(dpm,*it,load));
}
}
else if(SVFUtil::isa<StoreSVFGNode>(node))
else if(const StoreSVFGNode* store = SVFUtil::dyn_cast<StoreSVFGNode>(node))
{
if(store->getPAGSrcNode()->isPointer() == false)
return;

if(isMustAlias(getLoadDpm(dpm),dpm))
{
DBOUT(DDDA, SVFUtil::outs() << "+++must alias for load and store:");
Expand All @@ -217,17 +223,17 @@ class DDAVFSolver
{
if(propagateViaObj(*it,getLoadCVar(dpm)))
{
backtraceToStoreSrc(pts,getDPImWithOldCond(dpm,*it,node));
backtraceToStoreSrc(pts,getDPImWithOldCond(dpm,*it,store));

if(isStrongUpdate(storepts,SVFUtil::cast<StoreSVFGNode>(node)))
if(isStrongUpdate(storepts,store))
{
DBOUT(DDDA, SVFUtil::outs() << "backward strong update for obj " << dpm.getCurNodeID() << "\n");
DOSTAT(addSUStat(dpm,node);)
DOSTAT(addSUStat(dpm,store);)
}
else
{
DOSTAT(rmSUStat(dpm,node);)
backtraceAlongIndirectVF(pts,getDPImWithOldCond(dpm,*it,node));
DOSTAT(rmSUStat(dpm,store);)
backtraceAlongIndirectVF(pts,getDPImWithOldCond(dpm,*it,store));
}
}
else
Expand Down Expand Up @@ -347,7 +353,7 @@ class DDAVFSolver
{
const SVFGNode* node = oldDpm.getLoc();
NodeID obj = oldDpm.getCurNodeID();
if (_pag->isConstantObj(obj) || _pag->isNonPointerObj(obj))
if (_pag->isConstantObj(obj))
return;
const SVFGEdgeSet edgeSet(node->getInEdges());
for (SVFGNode::const_iterator it = edgeSet.begin(), eit = edgeSet.end(); it != eit; ++it)
Expand Down
4 changes: 0 additions & 4 deletions svf/include/MemoryModel/PointerAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,6 @@ class PointerAnalysis
{
return pag->isBlkObjOrConstantObj(ptd);
}
inline bool isNonPointerObj(NodeID ptd) const
{
return pag->isNonPointerObj(ptd);
}
//@}

/// Whether this object is heap or array
Expand Down
2 changes: 0 additions & 2 deletions svf/include/SVFIR/SVFIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,6 @@ class SVFIR : public IRGraph
return SymbolTableInfo::isConstantObj(id) ||
obj->isConstDataOrConstGlobal();
}
/// Whether an object can point to any other object or any of its fields is a pointer type.
bool isNonPointerObj(NodeID id) const;
//@}

/// Base and Offset methods for Value and Object node
Expand Down
2 changes: 0 additions & 2 deletions svf/include/SVFIR/SymbolTableInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ class MemObj
bool isConstDataOrConstGlobal() const;
bool isConstDataOrAggData() const;
bool hasPtrObj() const;
bool isNonPtrFieldObj(const APOffset& apOffset) const;
//@}

/// Operator overloading
Expand Down Expand Up @@ -651,7 +650,6 @@ class ObjTypeInfo
{
return hasFlag(HASPTR_OBJ);
}
virtual bool isNonPtrFieldObj(const APOffset& apOffset);
//@}
};

Expand Down
25 changes: 0 additions & 25 deletions svf/lib/SVFIR/SVFIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,31 +669,6 @@ void SVFIR::initialiseCandidatePointers()
candidatePointers.insert(nodeId);
}
}
/*!
* Return true if FIObjVar can point to any object
* Or a field GepObjVar can point to any object.
*/
bool SVFIR::isNonPointerObj(NodeID id) const
{
SVFVar* node = getGNode(id);
if (const FIObjVar* fiNode = SVFUtil::dyn_cast<FIObjVar>(node))
{
return (fiNode->getMemObj()->hasPtrObj()==false);
}
else if (const GepObjVar* gepNode = SVFUtil::dyn_cast<GepObjVar>(node))
{
return (gepNode->getMemObj()->isNonPtrFieldObj(gepNode->getConstantFieldIdx()));
}
else if (const DummyObjVar* dummyNode = SVFUtil::dyn_cast<DummyObjVar>(node))
{
return (dummyNode->getMemObj()->hasPtrObj()==false);
}
else
{
assert(false && "expecting a object node");
abort();
}
}
/*
* If this is a dummy node or node does not have incoming edges and outgoing edges we assume it is not a pointer here.
* However, if it is a pointer and it is an argument of a function definition, we assume it is a pointer here.
Expand Down
38 changes: 0 additions & 38 deletions svf/lib/SVFIR/SymbolTableInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,39 +362,6 @@ void SymbolTableInfo::dump()
outs() << "}\n";
}

/*!
* Whether a location set is a pointer type or not
*/
bool ObjTypeInfo::isNonPtrFieldObj(const APOffset& apOffset)
{
if (hasPtrObj() == false)
return true;

const SVFType* ety = type;

if (SVFUtil::isa<SVFStructType, SVFArrayType>(ety))
{
u32_t sz = 0;
if(Options::ModelArrays())
sz = SymbolTableInfo::SymbolInfo()->getTypeInfo(ety)->getFlattenElementTypes().size();
else
sz = SymbolTableInfo::SymbolInfo()->getTypeInfo(ety)->getFlattenFieldTypes().size();

if(sz <= (u32_t) apOffset)
{
writeWrnMsg("out of bound error when accessing the struct/array");
return false;
}

const SVFType* elemTy = SymbolTableInfo::SymbolInfo()->getFlatternedElemType(ety, apOffset);
return (elemTy->isPointerTy() == false);
}
else
{
return (hasPtrObj() == false);
}
}

/*!
* Set mem object to be field sensitive (up to maximum field limit)
*/
Expand Down Expand Up @@ -547,11 +514,6 @@ bool MemObj::hasPtrObj() const
return typeInfo->hasPtrObj();
}

bool MemObj::isNonPtrFieldObj(const APOffset& apOffset) const
{
return typeInfo->isNonPtrFieldObj(apOffset);
}

const std::string MemObj::toString() const
{
std::string str;
Expand Down
8 changes: 4 additions & 4 deletions svf/lib/WPA/Andersen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ bool Andersen::processLoad(NodeID node, const ConstraintEdge* load)
/// TODO: New copy edges are also added for black hole obj node to
/// make gcc in spec 2000 pass the flow-sensitive analysis.
/// Try to handle black hole obj in an appropriate way.
// if (pag->isBlkObjOrConstantObj(node) || isNonPointerObj(node))
if (pag->isConstantObj(node) || isNonPointerObj(node))
// if (pag->isBlkObjOrConstantObj(node))
if (pag->isConstantObj(node) || pag->getGNode(load->getDstID())->isPointer() == false)
return false;

numOfProcessedLoad++;
Expand All @@ -371,8 +371,8 @@ bool Andersen::processStore(NodeID node, const ConstraintEdge* store)
/// TODO: New copy edges are also added for black hole obj node to
/// make gcc in spec 2000 pass the flow-sensitive analysis.
/// Try to handle black hole obj in an appropriate way
// if (pag->isBlkObjOrConstantObj(node) || isNonPointerObj(node))
if (pag->isConstantObj(node) || isNonPointerObj(node))
// if (pag->isBlkObjOrConstantObj(node))
if (pag->isConstantObj(node) || pag->getGNode(store->getSrcID())->isPointer() == false)
return false;

numOfProcessedStore++;
Expand Down
42 changes: 23 additions & 19 deletions svf/lib/WPA/FlowSensitive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,30 +557,33 @@ bool FlowSensitive::processLoad(const LoadSVFGNode* load)
NodeID dstVar = load->getPAGDstNodeID();

const PointsTo& srcPts = getPts(load->getPAGSrcNodeID());
for (PointsTo::iterator ptdIt = srcPts.begin(); ptdIt != srcPts.end(); ++ptdIt)
{
NodeID ptd = *ptdIt;

if (pag->isConstantObj(ptd) || pag->isNonPointerObj(ptd))
continue;
// p = *q, the type of p must be a pointer
if(load->getPAGDstNode()->isPointer()) {
for (PointsTo::iterator ptdIt = srcPts.begin(); ptdIt != srcPts.end(); ++ptdIt)
{
NodeID ptd = *ptdIt;

if (unionPtsFromIn(load, ptd, dstVar))
changed = true;
if (pag->isConstantObj(ptd))
continue;

if (isFieldInsensitive(ptd))
{
/// If the ptd is a field-insensitive node, we should also get all field nodes'
/// points-to sets and pass them to pagDst.
const NodeBS& allFields = getAllFieldsObjVars(ptd);
for (NodeBS::iterator fieldIt = allFields.begin(), fieldEit = allFields.end();
fieldIt != fieldEit; ++fieldIt)
if (unionPtsFromIn(load, ptd, dstVar))
changed = true;

if (isFieldInsensitive(ptd))
{
if (unionPtsFromIn(load, *fieldIt, dstVar))
changed = true;
/// If the ptd is a field-insensitive node, we should also get all field nodes'
/// points-to sets and pass them to pagDst.
const NodeBS& allFields = getAllFieldsObjVars(ptd);
for (NodeBS::iterator fieldIt = allFields.begin(), fieldEit = allFields.end();
fieldIt != fieldEit; ++fieldIt)
{
if (unionPtsFromIn(load, *fieldIt, dstVar))
changed = true;
}
}
}
}

double end = stat->getClk();
loadTime += (end - start) / TIMEINTERVAL;
return changed;
Expand Down Expand Up @@ -609,13 +612,14 @@ bool FlowSensitive::processStore(const StoreSVFGNode* store)
double start = stat->getClk();
bool changed = false;

if(getPts(store->getPAGSrcNodeID()).empty() == false)
// *p = q, the type of q must be a pointer
if(getPts(store->getPAGSrcNodeID()).empty() == false && store->getPAGSrcNode()->isPointer())
{
for (PointsTo::iterator it = dstPts.begin(), eit = dstPts.end(); it != eit; ++it)
{
NodeID ptd = *it;

if (pag->isConstantObj(ptd) || pag->isNonPointerObj(ptd))
if (pag->isConstantObj(ptd))
continue;

if (unionPtsFromTop(store, store->getPAGSrcNodeID(), ptd))
Expand Down
57 changes: 31 additions & 26 deletions svf/lib/WPA/VersionedFlowSensitive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,32 +656,34 @@ bool VersionedFlowSensitive::processLoad(const LoadSVFGNode* load)
NodeID q = load->getPAGSrcNodeID();

const PointsTo& qpt = getPts(q);
for (NodeID o : qpt)
{
if (pag->isConstantObj(o) || pag->isNonPointerObj(o)) continue;

const Version c = getConsume(l, o);
if (c != invalidVersion && vPtD->unionPts(p, atKey(o, c)))
// p = *q, the type of p must be a pointer
if (load->getPAGDstNode()->isPointer()) {
for (NodeID o : qpt)
{
changed = true;
}
if (pag->isConstantObj(o)) continue;

if (isFieldInsensitive(o))
{
/// If o is a field-insensitive object, we should also get all field nodes'
/// points-to sets and pass them to p.
const NodeBS& fields = getAllFieldsObjVars(o);
for (NodeID of : fields)
const Version c = getConsume(l, o);
if (c != invalidVersion && vPtD->unionPts(p, atKey(o, c)))
{
const Version c = getConsume(l, of);
if (c != invalidVersion && vPtD->unionPts(p, atKey(of, c)))
changed = true;
}

if (isFieldInsensitive(o))
{
/// If o is a field-insensitive object, we should also get all field nodes'
/// points-to sets and pass them to p.
const NodeBS& fields = getAllFieldsObjVars(o);
for (NodeID of : fields)
{
changed = true;
const Version c = getConsume(l, of);
if (c != invalidVersion && vPtD->unionPts(p, atKey(of, c)))
{
changed = true;
}
}
}
}
}

double end = stat->getClk();
loadTime += (end - start) / TIMEINTERVAL;
return changed;
Expand All @@ -707,15 +709,18 @@ bool VersionedFlowSensitive::processStore(const StoreSVFGNode* store)

if (!qpt.empty())
{
for (NodeID o : ppt)
{
if (pag->isConstantObj(o) || pag->isNonPointerObj(o)) continue;

const Version y = getYield(l, o);
if (y != invalidVersion && vPtD->unionPts(atKey(o, y), q))
// *p = q, the type of q must be a pointer
if (store->getPAGSrcNode()->isPointer()) {
for (NodeID o : ppt)
{
changed = true;
changedObjects.set(o);
if (pag->isConstantObj(o)) continue;

const Version y = getYield(l, o);
if (y != invalidVersion && vPtD->unionPts(atKey(o, y), q))
{
changed = true;
changedObjects.set(o);
}
}
}
}
Expand Down

0 comments on commit 882bb47

Please sign in to comment.