Skip to content

Commit

Permalink
remove svfvalue in pagedge and svfg (#1625)
Browse files Browse the repository at this point in the history
* remove svfvalue in svfg and pagedge

* remove svfvalue in svfg and pagedge

* remove redundant variable
  • Loading branch information
jumormt authored Jan 9, 2025
1 parent f7e561e commit 4e366d1
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 57 deletions.
15 changes: 7 additions & 8 deletions svf-llvm/include/SVF-LLVM/SVFIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ class SVFIRBuilder: public llvm::InstVisitor<SVFIRBuilder>
AddrStmt* edge = addAddrEdge(src, dst);
if (inst.getArraySize())
{
SVFValue* arrSz = llvmModuleSet()->getSVFValue(inst.getArraySize());
edge->addArrSize(arrSz);
edge->addArrSize(pag->getGNode(getValueNode(inst.getArraySize())));
}
return edge;
}
Expand All @@ -334,8 +333,7 @@ class SVFIRBuilder: public llvm::InstVisitor<SVFIRBuilder>
if (cs->arg_size() > 0)
{
const llvm::Value* val = cs->getArgOperand(0);
SVFValue* svfval = llvmModuleSet()->getSVFValue(val);
edge->addArrSize(svfval);
edge->addArrSize(pag->getGNode(getValueNode(val)));
}
}
// Check if the function called is 'calloc' and process its arguments.
Expand All @@ -344,17 +342,18 @@ class SVFIRBuilder: public llvm::InstVisitor<SVFIRBuilder>
{
if (cs->arg_size() > 1)
{
edge->addArrSize(llvmModuleSet()->getSVFValue(cs->getArgOperand(0)));
edge->addArrSize(llvmModuleSet()->getSVFValue(cs->getArgOperand(1)));
edge->addArrSize(
pag->getGNode(getValueNode(cs->getArgOperand(0))));
edge->addArrSize(
pag->getGNode(getValueNode(cs->getArgOperand(1))));
}
}
else
{
if (cs->arg_size() > 0)
{
const llvm::Value* val = cs->getArgOperand(0);
SVFValue* svfval = llvmModuleSet()->getSVFValue(val);
edge->addArrSize(svfval);
edge->addArrSize(pag->getGNode(getValueNode(val)));
}
}
return edge;
Expand Down
2 changes: 1 addition & 1 deletion svf-llvm/lib/SVFIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ void SVFIRBuilder::setCurrentBBAndValueForPAGEdge(PAGEdge* edge)

assert(curVal && "current Val is nullptr?");
edge->setBB(curBB!=nullptr ? curBB : nullptr);
edge->setValue(curVal);
edge->setValue(pag->getGNode(pag->getValueNode(curVal)));
// backmap in valuToEdgeMap
pag->mapValueToEdge(curVal, edge);
ICFGNode* icfgNode = pag->getICFG()->getGlobalICFGNode();
Expand Down
16 changes: 7 additions & 9 deletions svf-llvm/tools/Example/svf-ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ using namespace SVF;
/*!
* An example to query alias results of two SVF values
*/
SVF::AliasResult aliasQuery(PointerAnalysis* pta, const SVFValue* v1, const SVFValue* v2)
SVF::AliasResult aliasQuery(PointerAnalysis* pta, const SVFVar* v1, const SVFVar* v2)
{
return pta->alias(v1, v2);
return pta->alias(v1->getId(), v2->getId());
}

/*!
* An example to print points-to set of an SVF value
*/
std::string printPts(PointerAnalysis* pta, const SVFValue* svfval)
std::string printPts(PointerAnalysis* pta, const SVFVar* svfval)
{

std::string str;
raw_string_ostream rawstr(str);

NodeID pNodeId = pta->getPAG()->getValueNode(svfval);
NodeID pNodeId = svfval->getId();
const PointsTo& pts = pta->getPts(pNodeId);
for (PointsTo::iterator ii = pts.begin(), ie = pts.end();
ii != ie; ii++)
Expand Down Expand Up @@ -105,13 +105,11 @@ void dummyVisit(const VFGNode* node)
/*!
* An example to query/collect all the uses of a definition of a value along value-flow graph (VFG)
*/
void traverseOnVFG(const SVFG* vfg, const SVFValue* svfval)
void traverseOnVFG(const SVFG* vfg, const SVFVar* svfval)
{
SVFIR* pag = SVFIR::getPAG();
PAGNode* pNode = pag->getGNode(pag->getValueNode(svfval));
if (!vfg->hasDefSVFGNode(pNode))
if (!vfg->hasDefSVFGNode(svfval))
return;
const VFGNode* vNode = vfg->getDefSVFGNode(pNode);
const VFGNode* vNode = vfg->getDefSVFGNode(svfval);
FIFOWorkList<const VFGNode*> worklist;
Set<const VFGNode*> visited;
worklist.push(vNode);
Expand Down
14 changes: 8 additions & 6 deletions svf/include/Graphs/VFGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class VFGNode : public GenericVFGNodeTy
}

/// Return the corresponding LLVM value, if possible, nullptr otherwise.
virtual const SVFValue* getValue() const
virtual const SVFVar* getValue() const
{
return nullptr;
}
Expand Down Expand Up @@ -190,7 +190,7 @@ class StmtVFGNode : public VFGNode
}
//@}

const SVFValue* getValue() const override;
const SVFVar* getValue() const override;
const std::string toString() const override;
};

Expand Down Expand Up @@ -401,7 +401,9 @@ class CmpVFGNode: public VFGNode

const NodeBS getDefSVFVars() const override;

const SVFValue* getValue() const override;
const SVFVar* getValue() const override;


const std::string toString() const override;
};

Expand Down Expand Up @@ -476,7 +478,7 @@ class BinaryOPVFGNode: public VFGNode

const NodeBS getDefSVFVars() const override;

const SVFValue* getValue() const override;
const SVFVar* getValue() const override;
const std::string toString() const override;
};

Expand Down Expand Up @@ -736,7 +738,7 @@ class PHIVFGNode : public VFGNode

const NodeBS getDefSVFVars() const override;

const SVFValue* getValue() const override;
const SVFVar* getValue() const override;
const std::string toString() const override;
};

Expand Down Expand Up @@ -879,7 +881,7 @@ class ArgumentVFGNode : public VFGNode
}
//@}

const SVFValue* getValue() const override;
const SVFVar* getValue() const override;
const std::string toString() const override;
};

Expand Down
21 changes: 8 additions & 13 deletions svf/include/SVFIR/SVFStatements.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class SVFStmt : public GenericPAGEdgeTy
};

private:
const SVFValue* value; ///< LLVM value
const SVFVar* value; ///< LLVM value
const SVFBasicBlock* basicBlock; ///< LLVM BasicBlock
ICFGNode* icfgNode; ///< ICFGNode
EdgeID edgeId; ///< Edge ID
Expand Down Expand Up @@ -134,20 +134,15 @@ class SVFStmt : public GenericPAGEdgeTy

/// Get/set methods for llvm instruction
//@{
inline const SVFInstruction* getInst() const
{
if (const SVFInstruction* i = SVFUtil::dyn_cast<SVFInstruction>(value))
return i;
return nullptr;
}
inline void setValue(const SVFValue* val)

inline void setValue(const SVFVar* val)
{
value = val;
}
inline const SVFValue* getValue() const
{
inline const SVFVar* getValue() const {
return value;
}

inline void setBB(const SVFBasicBlock* bb)
{
basicBlock = bb;
Expand Down Expand Up @@ -321,7 +316,7 @@ class AddrStmt: public AssignStmt
AddrStmt(const AddrStmt&); ///< place holder
void operator=(const AddrStmt&); ///< place holder

std::vector<SVFValue*> arrSize; ///< Array size of the allocated memory
std::vector<SVFVar*> arrSize; ///< Array size of the allocated memory

public:
/// Methods for support type inquiry through isa, cast, and dyn_cast:
Expand All @@ -345,13 +340,13 @@ class AddrStmt: public AssignStmt

virtual const std::string toString() const override;

inline void addArrSize(SVFValue* size) //TODO:addSizeVar
inline void addArrSize(SVFVar* size) //TODO:addSizeVar
{
arrSize.push_back(size);
}

///< get array size of the allocated memory
inline const std::vector<SVFValue*>& getArrSize() const //TODO:getSizeVars
inline const std::vector<SVFVar*>& getArrSize() const //TODO:getSizeVars
{
return arrSize;
}
Expand Down
11 changes: 5 additions & 6 deletions svf/lib/AE/Core/AbstractState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@ const SVFType* AbstractState::getPointeeElement(NodeID id)

u32_t AbstractState::getAllocaInstByteSize(const AddrStmt *addr)
{
SVFIR* svfir = PAG::getPAG();
if (const ObjVar* objvar = SVFUtil::dyn_cast<ObjVar>(addr->getRHSVar()))
{
objvar->getType();
Expand All @@ -497,18 +496,18 @@ u32_t AbstractState::getAllocaInstByteSize(const AddrStmt *addr)

else
{
const std::vector<SVFValue*>& sizes = addr->getArrSize();
const std::vector<SVFVar*>& sizes = addr->getArrSize();
// Default element size is set to 1.
u32_t elementSize = 1;
u64_t res = elementSize;
for (const SVFValue* value: sizes)
for (const SVFVar* value: sizes)
{
if (!inVarToValTable(svfir->getValueNode(value)))
if (!inVarToValTable(value->getId()))
{
(*this)[svfir->getValueNode(value)] = IntervalValue(Options::MaxFieldLimit());
(*this)[value->getId()] = IntervalValue(Options::MaxFieldLimit());
}
IntervalValue itv =
(*this)[svfir->getValueNode(value)].getInterval();
(*this)[value->getId()].getInterval();
res = res * itv.ub().getIntNumeral() > Options::MaxFieldLimit()? Options::MaxFieldLimit(): res * itv.ub().getIntNumeral();
}
return (u32_t)res;
Expand Down
18 changes: 9 additions & 9 deletions svf/lib/Graphs/VFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,29 +1073,29 @@ const SVFFunction* VFG::isFunEntryVFGNode(const VFGNode* node) const
}


const SVFValue* StmtVFGNode::getValue() const
const SVFVar* StmtVFGNode::getValue() const
{
return getPAGEdge()->getValue();
}

const SVFValue* CmpVFGNode::getValue() const
const SVFVar* CmpVFGNode::getValue() const
{
return getRes()->getValue();
return getRes();
}

const SVFValue* BinaryOPVFGNode::getValue() const
const SVFVar* BinaryOPVFGNode::getValue() const
{
return getRes()->getValue();
return getRes();
}

const SVFValue* PHIVFGNode::getValue() const
const SVFVar* PHIVFGNode::getValue() const
{
return getRes()->hasValue() ? getRes()->getValue(): nullptr;
return getRes()->hasValue() ? getRes(): nullptr;
}

const SVFValue* ArgumentVFGNode::getValue() const
const SVFVar* ArgumentVFGNode::getValue() const
{
return param->hasValue() ? param->getValue() : nullptr;
return param->hasValue() ? param : nullptr;
}

/*!
Expand Down
2 changes: 1 addition & 1 deletion svf/lib/MTA/MTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void MTA::detect(SVFModule* module)
for (Set<const StoreStmt*>::const_iterator sit = stores.begin(), esit = stores.end(); sit != esit; ++sit)
{
const StoreStmt* store = *sit;
if(load->getInst()==nullptr || store->getInst()==nullptr)
if(SVFUtil::isa<GlobalICFGNode>(load->getICFGNode()) || SVFUtil::isa<GlobalICFGNode>(store->getICFGNode()))
continue;
if(mhp->mayHappenInParallelInst(load->getICFGNode(),store->getICFGNode()) && pta->alias(load->getRHSVarID(),store->getLHSVarID()))
if(lsa->isProtectedByCommonLock(load->getICFGNode(),store->getICFGNode()) == false)
Expand Down
9 changes: 5 additions & 4 deletions svf/lib/SABER/SaberCondAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,27 +399,28 @@ bool SaberCondAllocator::isTestNotNullExpr(const ICFGNode* test) const
bool SaberCondAllocator::isTestContainsNullAndTheValue(const CmpStmt *cmp) const
{

// must be val var?
const SVFVar* op0 = cmp->getOpVar(0);
const SVFVar* op1 = cmp->getOpVar(1);
if (SVFUtil::isa<ConstantNullPtrValVar>(op1))
{
Set<const SVFValue* > inDirVal;
Set<const SVFVar* > inDirVal;
inDirVal.insert(getCurEvalSVFGNode()->getValue());
for (const auto &it: getCurEvalSVFGNode()->getOutEdges())
{
inDirVal.insert(it->getDstNode()->getValue());
}
return inDirVal.find(op0->getValue()) != inDirVal.end();
return inDirVal.find(op0) != inDirVal.end();
}
else if (SVFUtil::isa<ConstantNullPtrValVar>(op0))
{
Set<const SVFValue* > inDirVal;
Set<const SVFVar* > inDirVal;
inDirVal.insert(getCurEvalSVFGNode()->getValue());
for (const auto &it: getCurEvalSVFGNode()->getOutEdges())
{
inDirVal.insert(it->getDstNode()->getValue());
}
return inDirVal.find(op1->getValue()) != inDirVal.end();
return inDirVal.find(op1) != inDirVal.end();
}
return false;
}
Expand Down

0 comments on commit 4e366d1

Please sign in to comment.