Skip to content

Commit

Permalink
update changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonZhongZexin authored and JasonZhongZexin committed Sep 12, 2023
1 parent c7e6803 commit 7f9cc4f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 33 deletions.
6 changes: 2 additions & 4 deletions svf/include/SVFIR/SVFIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,13 @@ class SVFIR : public IRGraph
return node->getMemObj();
}
//@}

void addGepObjNode(const NodeID& base, const APOffset& apOffset, const NodeID id);

/// Get a field SVFIR Object node according to base mem obj and offset
NodeID getGepObjVar(const MemObj* obj, const APOffset& ap);
/// Get a field obj SVFIR node according to a mem obj and a given offset
NodeID getGepObjVar(NodeID id, const APOffset& ap) ;
/// Add a field obj node, this method can only invoked by getGepObjVar
NodeID addGepObjNode(const MemObj* obj, const APOffset& apOffset, const NodeID gepId);
/// Get a field-insensitive obj SVFIR node according to a mem obj
//@{
inline NodeID getFIObjVar(const MemObj* obj) const
Expand Down Expand Up @@ -561,8 +561,6 @@ class SVFIR : public IRGraph

/// Add a temp field value node, this method can only invoked by getGepValVar
NodeID addGepValNode(const SVFValue* curInst,const SVFValue* val, const AccessPath& ap, NodeID i, const SVFType* type);
/// Add a field obj node, this method can only invoked by getGepObjVar
NodeID addGepObjNode(const MemObj* obj, const APOffset& apOffset);
/// Add a field-insensitive node, this method can only invoked by getFIGepObjNode
NodeID addFIObjNode(const MemObj* obj);
//@}
Expand Down
15 changes: 14 additions & 1 deletion svf/lib/MemoryModel/PointerAnalysisImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,20 @@ void BVDataPTAImpl::readGepObjVarMapFromFile(std::ifstream& F)
ss >> base >> offset >>id;
SVFIR::NodeOffsetMap::const_iterator iter = gepObjVarMap.find(std::make_pair(base, offset));
if (iter == gepObjVarMap.end())
pag->addGepObjNode(base, offset, id);
{
SVFVar* node = pag->getGNode(base);
const MemObj* obj = nullptr;
if (GepObjVar* gepObjVar = SVFUtil::dyn_cast<GepObjVar>(node))
obj = gepObjVar->getMemObj();
else if (FIObjVar* baseNode = SVFUtil::dyn_cast<FIObjVar>(node))
obj = baseNode->getMemObj();
else if (DummyObjVar* baseNode = SVFUtil::dyn_cast<DummyObjVar>(node))
obj = baseNode->getMemObj();
else
assert(false && "new gep obj node kind?");
pag->addGepObjNode(obj, offset, id);
NodeIDAllocator::get()->increaseNumOfObjAndNodes();
}


}
Expand Down
33 changes: 6 additions & 27 deletions svf/lib/SVFIR/SVFIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,11 @@ NodeID SVFIR::getGepObjVar(const MemObj* obj, const APOffset& apOffset)

NodeOffsetMap::iterator iter = GepObjVarMap.find(std::make_pair(base, newLS));
if (iter == GepObjVarMap.end())
return addGepObjNode(obj, newLS);
{
NodeID gepId = NodeIDAllocator::get()->allocateGepObjectId(base, apOffset, Options::MaxFieldLimit());
NodeIDAllocator::get()->increaseNumOfObjAndNodes();
return addGepObjNode(obj, newLS,gepId);
}
else
return iter->second;

Expand All @@ -443,44 +447,19 @@ NodeID SVFIR::getGepObjVar(const MemObj* obj, const APOffset& apOffset)
/*!
* Add a field obj node, this method can only invoked by getGepObjVar
*/
NodeID SVFIR::addGepObjNode(const MemObj* obj, const APOffset& apOffset)
NodeID SVFIR::addGepObjNode(const MemObj* obj, const APOffset& apOffset, const NodeID gepId)
{
//assert(findPAGNode(i) == false && "this node should not be created before");
NodeID base = obj->getId();
assert(0==GepObjVarMap.count(std::make_pair(base, apOffset))
&& "this node should not be created before");

NodeID gepId = NodeIDAllocator::get()->allocateGepObjectId(base, apOffset, Options::MaxFieldLimit());
GepObjVarMap[std::make_pair(base, apOffset)] = gepId;
GepObjVar *node = new GepObjVar(obj, gepId, apOffset);
memToFieldsMap[base].set(gepId);
return addObjNode(obj->getValue(), node, gepId);
}

void SVFIR::addGepObjNode(const NodeID& base, const APOffset& apOffset, const NodeID gepId)
{
SVFVar* node = pag->getGNode(base);
assert(0==GepObjVarMap.count(std::make_pair(base, apOffset))
&& "this node should not be created before");
GepObjVarMap[std::make_pair(base, apOffset)] = gepId;
NodeIDAllocator::get()->increaseNumOfObjAndNodes();
memToFieldsMap[base].set(gepId);
const MemObj* obj;
if (GepObjVar* gepObjVar = SVFUtil::dyn_cast<GepObjVar>(node))
obj = gepObjVar->getMemObj();
else if (FIObjVar* baseNode = SVFUtil::dyn_cast<FIObjVar>(node))
obj = baseNode->getMemObj();
else if (DummyObjVar* baseNode = SVFUtil::dyn_cast<DummyObjVar>(node))
obj = baseNode->getMemObj();
else
assert(false && "new gep obj node kind?");
if (obj != nullptr)
{
GepObjVar *gepNode = new GepObjVar(obj, gepId, apOffset);
addObjNode(obj->getValue(), gepNode, gepId);
}
}

/*!
* Add a field-insensitive node, this method can only invoked by getFIGepObjNode
*/
Expand Down
2 changes: 1 addition & 1 deletion svf/lib/Util/NodeIDAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ NodeID NodeIDAllocator::allocateGepObjectId(NodeID base, u32_t offset, u32_t max
assert(false && "NodeIDAllocator::allocateGepObjectId: unimplemented node allocation strategy");
}

increaseNumOfObjAndNodes();


assert(id != 0 && "NodeIDAllocator::allocateGepObjectId: ID not allocated");
return id;
Expand Down

0 comments on commit 7f9cc4f

Please sign in to comment.