diff --git a/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h b/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h index 86c3c8e1f..59768e174 100644 --- a/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h +++ b/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h @@ -307,8 +307,7 @@ class SVFIRBuilder: public llvm::InstVisitor 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; } @@ -334,8 +333,7 @@ class SVFIRBuilder: public llvm::InstVisitor 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. @@ -344,8 +342,10 @@ class SVFIRBuilder: public llvm::InstVisitor { 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 @@ -353,8 +353,7 @@ class SVFIRBuilder: public llvm::InstVisitor 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; diff --git a/svf-llvm/lib/SVFIRBuilder.cpp b/svf-llvm/lib/SVFIRBuilder.cpp index a9469fa1c..0ee96aec3 100644 --- a/svf-llvm/lib/SVFIRBuilder.cpp +++ b/svf-llvm/lib/SVFIRBuilder.cpp @@ -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(); diff --git a/svf-llvm/tools/Example/svf-ex.cpp b/svf-llvm/tools/Example/svf-ex.cpp index 7749140f8..c18301cb4 100644 --- a/svf-llvm/tools/Example/svf-ex.cpp +++ b/svf-llvm/tools/Example/svf-ex.cpp @@ -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++) @@ -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 worklist; Set visited; worklist.push(vNode); diff --git a/svf/include/Graphs/VFGNode.h b/svf/include/Graphs/VFGNode.h index fee444f59..ea06d56a4 100644 --- a/svf/include/Graphs/VFGNode.h +++ b/svf/include/Graphs/VFGNode.h @@ -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; } @@ -190,7 +190,7 @@ class StmtVFGNode : public VFGNode } //@} - const SVFValue* getValue() const override; + const SVFVar* getValue() const override; const std::string toString() const override; }; @@ -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; }; @@ -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; }; @@ -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; }; @@ -879,7 +881,7 @@ class ArgumentVFGNode : public VFGNode } //@} - const SVFValue* getValue() const override; + const SVFVar* getValue() const override; const std::string toString() const override; }; diff --git a/svf/include/SVFIR/SVFStatements.h b/svf/include/SVFIR/SVFStatements.h index 45a5d8c71..f90bc6a10 100644 --- a/svf/include/SVFIR/SVFStatements.h +++ b/svf/include/SVFIR/SVFStatements.h @@ -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 @@ -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(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; @@ -321,7 +316,7 @@ class AddrStmt: public AssignStmt AddrStmt(const AddrStmt&); ///< place holder void operator=(const AddrStmt&); ///< place holder - std::vector arrSize; ///< Array size of the allocated memory + std::vector arrSize; ///< Array size of the allocated memory public: /// Methods for support type inquiry through isa, cast, and dyn_cast: @@ -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& getArrSize() const //TODO:getSizeVars + inline const std::vector& getArrSize() const //TODO:getSizeVars { return arrSize; } diff --git a/svf/lib/AE/Core/AbstractState.cpp b/svf/lib/AE/Core/AbstractState.cpp index 4006694d7..913314ed3 100644 --- a/svf/lib/AE/Core/AbstractState.cpp +++ b/svf/lib/AE/Core/AbstractState.cpp @@ -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(addr->getRHSVar())) { objvar->getType(); @@ -497,18 +496,18 @@ u32_t AbstractState::getAllocaInstByteSize(const AddrStmt *addr) else { - const std::vector& sizes = addr->getArrSize(); + const std::vector& 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; diff --git a/svf/lib/Graphs/VFG.cpp b/svf/lib/Graphs/VFG.cpp index dd0924e82..fc671ba56 100644 --- a/svf/lib/Graphs/VFG.cpp +++ b/svf/lib/Graphs/VFG.cpp @@ -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; } /*! diff --git a/svf/lib/MTA/MTA.cpp b/svf/lib/MTA/MTA.cpp index ac4a7b1c2..0f614f255 100644 --- a/svf/lib/MTA/MTA.cpp +++ b/svf/lib/MTA/MTA.cpp @@ -164,7 +164,7 @@ void MTA::detect(SVFModule* module) for (Set::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(load->getICFGNode()) || SVFUtil::isa(store->getICFGNode())) continue; if(mhp->mayHappenInParallelInst(load->getICFGNode(),store->getICFGNode()) && pta->alias(load->getRHSVarID(),store->getLHSVarID())) if(lsa->isProtectedByCommonLock(load->getICFGNode(),store->getICFGNode()) == false) diff --git a/svf/lib/SABER/SaberCondAllocator.cpp b/svf/lib/SABER/SaberCondAllocator.cpp index 92e80f367..5628c1ad5 100644 --- a/svf/lib/SABER/SaberCondAllocator.cpp +++ b/svf/lib/SABER/SaberCondAllocator.cpp @@ -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(op1)) { - Set inDirVal; + Set 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(op0)) { - Set inDirVal; + Set 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; }