diff --git a/svf/include/SVFIR/SVFIR.h b/svf/include/SVFIR/SVFIR.h index 051314ee5..17541e7d8 100644 --- a/svf/include/SVFIR/SVFIR.h +++ b/svf/include/SVFIR/SVFIR.h @@ -174,6 +174,11 @@ class SVFIR : public IRGraph assert(icfg->totalICFGNode>0 && "empty ICFG! Build SVF IR first!"); return icfg; } + + inline bool isGlobalVar(const SVFVar* var) const { + return SVFUtil::isa(var) || SVFUtil::isa(var); + } + /// Set/Get CHG inline void setCHG(CommonCHGraph* c) { @@ -601,7 +606,7 @@ class SVFIR : public IRGraph inline NodeID addGlobalValueValNode(const SVFValue* curInst, const NodeID i, const ICFGNode* icfgNode) { - SVFVar* node = new GlobalValueValVar(curInst, i, icfgNode); + SVFVar* node = new GlobalValVar(curInst, i, icfgNode); return addNode(node, i); } @@ -636,7 +641,7 @@ class SVFIR : public IRGraph inline NodeID addGlobalValueObjNode(const SVFValue* curInst, const NodeID i) { const MemObj* mem = getMemObj(curInst); - GlobalValueObjVar* node = new GlobalValueObjVar(curInst, mem->getId(), mem); + GlobalObjVar* node = new GlobalObjVar(curInst, mem->getId(), mem); return addObjNode(mem->getValue(), node, mem->getId()); } @@ -648,7 +653,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 diff --git a/svf/include/SVFIR/SVFVariables.h b/svf/include/SVFIR/SVFVariables.h index 2c4a9fb71..abe73fdbc 100644 --- a/svf/include/SVFIR/SVFVariables.h +++ b/svf/include/SVFIR/SVFVariables.h @@ -731,7 +731,7 @@ class ConstantDataValVar: public ValVar virtual const std::string toString() const; }; -class GlobalValueValVar : public ValVar +class GlobalValVar : public ValVar { friend class SVFIRWriter; friend class SVFIRReader; @@ -762,7 +762,7 @@ class GlobalValueValVar : public ValVar //@} /// Constructor - GlobalValueValVar(const SVFValue* val, NodeID i, const ICFGNode* icn, + GlobalValVar(const SVFValue* val, NodeID i, const ICFGNode* icn, PNODEK ty = GlobalValueValNode) : ValVar(val, i, ty, icn) { @@ -957,18 +957,18 @@ class ConstantNullPtrValVar: public ConstantDataValVar virtual const std::string toString() const; }; -class GlobalValueObjVar: public FIObjVar { +class GlobalObjVar : public FIObjVar { friend class SVFIRWriter; friend class SVFIRReader; private: /// Constructor to create empty ObjVar (for SVFIRReader/deserialization) - GlobalValueObjVar(NodeID i, PNODEK ty = GlobalValueObjNode) : FIObjVar(i, ty) {} + GlobalObjVar(NodeID i, PNODEK ty = GlobalValueObjNode) : FIObjVar(i, ty) {} public: /// Methods for support type inquiry through isa, cast, and dyn_cast: //@{ - static inline bool classof(const GlobalValueObjVar*) + static inline bool classof(const GlobalObjVar*) { return true; } @@ -995,7 +995,7 @@ class GlobalValueObjVar: public FIObjVar { //@} /// Constructor - GlobalValueObjVar(const SVFValue* val, NodeID i, const MemObj* mem, + GlobalObjVar(const SVFValue* val, NodeID i, const MemObj* mem, PNODEK ty = GlobalValueObjNode): FIObjVar(val, i,mem,ty){ } diff --git a/svf/lib/AE/Core/AbstractState.cpp b/svf/lib/AE/Core/AbstractState.cpp index fe9059234..55edd6fe0 100644 --- a/svf/lib/AE/Core/AbstractState.cpp +++ b/svf/lib/AE/Core/AbstractState.cpp @@ -200,7 +200,7 @@ void AbstractState::initObjVar(ObjVar* objVar) { (*this)[varId] = IntervalValue(0, 0); } - else if (SVFUtil::isa(objVar)) + else if (SVFUtil::isa(objVar)) { (*this)[varId] = AddressValue(AbstractState::getVirtualMemAddress(varId)); } diff --git a/svf/lib/MemoryModel/PointerAnalysis.cpp b/svf/lib/MemoryModel/PointerAnalysis.cpp index 54359e9e1..f74d00ffa 100644 --- a/svf/lib/MemoryModel/PointerAnalysis.cpp +++ b/svf/lib/MemoryModel/PointerAnalysis.cpp @@ -446,12 +446,12 @@ void PointerAnalysis::getVFnsFromPts(const CallICFGNode* cs, const PointsTo &tar if (ptdnode->hasValue()) { // ptd is global obj var or ptd's base is global val/obj var - if (SVFUtil::isa(ptdnode)) { + if (pag->isGlobalVar(ptdnode)) { const SVFGlobalValue* globalValue = SVFUtil::dyn_cast(ptdnode->getValue()); if (chaVtbls.find(globalValue) != chaVtbls.end()) vtbls.insert(globalValue); } else if (const GepObjVar *gep_vtbl = SVFUtil::dyn_cast(ptdnode)) { - if (SVFUtil::isa(pag->getGNode(gep_vtbl->getBaseNode()))) { + if (SVFUtil::isa(pag->getGNode(gep_vtbl->getBaseNode()))) { const SVFGlobalValue* globalValue = SVFUtil::dyn_cast(gep_vtbl->getValue()); if (chaVtbls.find(globalValue) != chaVtbls.end()) vtbls.insert(globalValue); diff --git a/svf/lib/SABER/SaberCondAllocator.cpp b/svf/lib/SABER/SaberCondAllocator.cpp index ef074ce90..15d876241 100644 --- a/svf/lib/SABER/SaberCondAllocator.cpp +++ b/svf/lib/SABER/SaberCondAllocator.cpp @@ -401,14 +401,6 @@ bool SaberCondAllocator::isTestContainsNullAndTheValue(const CmpStmt *cmp) const const SVFVar* op0 = cmp->getOpVar(0); const SVFVar* op1 = cmp->getOpVar(1); - bool a = SVFUtil::dyn_cast(op0) || - SVFUtil::dyn_cast(op0); - bool b = SVFUtil::dyn_cast(op1) || - SVFUtil::dyn_cast(op1); - bool c = SVFUtil::dyn_cast(op0->getValue()); - bool d = SVFUtil::dyn_cast(op1->getValue()); - assert(a == c); - assert(b == d); if (SVFUtil::isa(op1)) { Set inDirVal; diff --git a/svf/lib/SABER/SaberSVFGBuilder.cpp b/svf/lib/SABER/SaberSVFGBuilder.cpp index 96fd1eacc..8adb4d948 100644 --- a/svf/lib/SABER/SaberSVFGBuilder.cpp +++ b/svf/lib/SABER/SaberSVFGBuilder.cpp @@ -82,7 +82,7 @@ void SaberSVFGBuilder::collectGlobals(BVDataPTAImpl* pta) if(SVFUtil::isa(pag->getGNode(gepobj->getBaseNode()))) continue; } - if(pagNode->hasValue() && SVFUtil::isa(pagNode)) + if(pagNode->hasValue() && pag->isGlobalVar(pagNode)) worklist.push_back(it->first); } diff --git a/svf/lib/SVFIR/SVFFileSystem.cpp b/svf/lib/SVFIR/SVFFileSystem.cpp index df281f506..e2759a884 100644 --- a/svf/lib/SVFIR/SVFFileSystem.cpp +++ b/svf/lib/SVFIR/SVFFileSystem.cpp @@ -227,13 +227,13 @@ cJSON* SVFIRWriter::virtToJson(const SVFVar* var) CASE(FunObjNode, FunObjVar); CASE(FunValNode, FunValVar); CASE(ConstantDataValNode, ConstantDataValVar); - CASE(GlobalValueValNode, GlobalValueValVar); + CASE(GlobalValueValNode, GlobalValVar); CASE(BlackHoleNode, BlackHoleVar); CASE(ConstantFPValNode, ConstantFPValVar); CASE(ConstantIntValNode, ConstantIntValVar); CASE(ConstantNullptrValNode, ConstantNullPtrValVar); CASE(ConstantDataObjNode, ConstantDataObjVar); - CASE(GlobalValueObjNode, GlobalValueObjVar); + CASE(GlobalValueObjNode, GlobalObjVar); CASE(ConstantFPObjNode, ConstantFPObjVar); CASE(ConstantIntObjNode, ConstantIntObjVar); CASE(ConstantNullptrObjNode, ConstantNullPtrObjVar); diff --git a/svf/lib/SVFIR/SVFVariables.cpp b/svf/lib/SVFIR/SVFVariables.cpp index bc30cba7e..fde2ca38b 100644 --- a/svf/lib/SVFIR/SVFVariables.cpp +++ b/svf/lib/SVFIR/SVFVariables.cpp @@ -221,7 +221,7 @@ const std::string ConstantDataValVar::toString() const { return rawstr.str(); } -const std::string GlobalValueValVar::toString() const { +const std::string GlobalValVar::toString() const { std::string str; std::stringstream rawstr(str); rawstr << "GlobalValueValVar ID: " << getId(); @@ -260,7 +260,7 @@ const std::string ConstantIntValVar::toString() const { const std::string ConstantNullPtrValVar::toString() const { std::string str; std::stringstream rawstr(str); - rawstr << "ConstantObjVar ID: " << getId(); + rawstr << "ConstantNullPtrValVar ID: " << getId(); if (Options::ShowSVFIRValue()) { rawstr << "\n"; @@ -269,8 +269,7 @@ const std::string ConstantNullPtrValVar::toString() const { return rawstr.str(); } - -const std::string GlobalValueObjVar::toString() const { +const std::string GlobalObjVar::toString() const { std::string str; std::stringstream rawstr(str); rawstr << "GlobalValueObjNode ID: " << getId();