Skip to content

Commit

Permalink
refactor GlobalClass, and remove unused codes
Browse files Browse the repository at this point in the history
  • Loading branch information
bjjwwang committed Dec 13, 2024
1 parent 713318a commit c4a2cc0
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 27 deletions.
10 changes: 7 additions & 3 deletions svf/include/SVFIR/SVFIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<GlobalValVar>(var) || SVFUtil::isa<GlobalObjVar>(var);
}

/// Set/Get CHG
inline void setCHG(CommonCHGraph* c)
{
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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());
}

Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions svf/include/SVFIR/SVFVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
Expand All @@ -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){

}
Expand Down
2 changes: 1 addition & 1 deletion svf/lib/AE/Core/AbstractState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void AbstractState::initObjVar(ObjVar* objVar)
{
(*this)[varId] = IntervalValue(0, 0);

Check warning on line 201 in svf/lib/AE/Core/AbstractState.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/AE/Core/AbstractState.cpp#L201

Added line #L201 was not covered by tests
}
else if (SVFUtil::isa<GlobalValueObjVar>(objVar))
else if (SVFUtil::isa<GlobalObjVar>(objVar))
{
(*this)[varId] = AddressValue(AbstractState::getVirtualMemAddress(varId));
}
Expand Down
4 changes: 2 additions & 2 deletions svf/lib/MemoryModel/PointerAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GlobalValueValVar, GlobalValueObjVar>(ptdnode)) {
if (pag->isGlobalVar(ptdnode)) {
const SVFGlobalValue* globalValue = SVFUtil::dyn_cast<SVFGlobalValue>(ptdnode->getValue());
if (chaVtbls.find(globalValue) != chaVtbls.end())
vtbls.insert(globalValue);
} else if (const GepObjVar *gep_vtbl = SVFUtil::dyn_cast<GepObjVar>(ptdnode)) {
if (SVFUtil::isa<GlobalValueValVar, GlobalValueObjVar>(pag->getGNode(gep_vtbl->getBaseNode()))) {
if (SVFUtil::isa<GlobalValVar, GlobalObjVar>(pag->getGNode(gep_vtbl->getBaseNode()))) {
const SVFGlobalValue* globalValue = SVFUtil::dyn_cast<SVFGlobalValue>(gep_vtbl->getValue());
if (chaVtbls.find(globalValue) != chaVtbls.end())
vtbls.insert(globalValue);
Expand Down
8 changes: 0 additions & 8 deletions svf/lib/SABER/SaberCondAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConstantNullPtrValVar>(op0) ||
SVFUtil::dyn_cast<ConstantNullPtrObjVar>(op0);
bool b = SVFUtil::dyn_cast<ConstantNullPtrValVar>(op1) ||
SVFUtil::dyn_cast<ConstantNullPtrObjVar>(op1);
bool c = SVFUtil::dyn_cast<SVFConstantNullPtr>(op0->getValue());
bool d = SVFUtil::dyn_cast<SVFConstantNullPtr>(op1->getValue());
assert(a == c);
assert(b == d);
if (SVFUtil::isa<ConstantNullPtrValVar, ConstantNullPtrObjVar>(op1))
{
Set<const SVFValue* > inDirVal;
Expand Down
2 changes: 1 addition & 1 deletion svf/lib/SABER/SaberSVFGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void SaberSVFGBuilder::collectGlobals(BVDataPTAImpl* pta)
if(SVFUtil::isa<DummyObjVar>(pag->getGNode(gepobj->getBaseNode())))
continue;
}
if(pagNode->hasValue() && SVFUtil::isa<GlobalValueValVar, GlobalValueObjVar>(pagNode))
if(pagNode->hasValue() && pag->isGlobalVar(pagNode))
worklist.push_back(it->first);
}

Expand Down
4 changes: 2 additions & 2 deletions svf/lib/SVFIR/SVFFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 232 in svf/lib/SVFIR/SVFFileSystem.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/SVFIR/SVFFileSystem.cpp#L232

Added line #L232 was not covered by tests
CASE(ConstantIntValNode, ConstantIntValVar);
CASE(ConstantNullptrValNode, ConstantNullPtrValVar);
CASE(ConstantDataObjNode, ConstantDataObjVar);
CASE(GlobalValueObjNode, GlobalValueObjVar);
CASE(GlobalValueObjNode, GlobalObjVar);

Check warning on line 236 in svf/lib/SVFIR/SVFFileSystem.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/SVFIR/SVFFileSystem.cpp#L234-L236

Added lines #L234 - L236 were not covered by tests
CASE(ConstantFPObjNode, ConstantFPObjVar);
CASE(ConstantIntObjNode, ConstantIntObjVar);
CASE(ConstantNullptrObjNode, ConstantNullPtrObjVar);
Expand Down
7 changes: 3 additions & 4 deletions svf/lib/SVFIR/SVFVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ const std::string ConstantDataValVar::toString() const {
return rawstr.str();
}

Check warning on line 222 in svf/lib/SVFIR/SVFVariables.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/SVFIR/SVFVariables.cpp#L221-L222

Added lines #L221 - L222 were not covered by tests

const std::string GlobalValueValVar::toString() const {
const std::string GlobalValVar::toString() const {
std::string str;
std::stringstream rawstr(str);
rawstr << "GlobalValueValVar ID: " << getId();
Expand Down Expand Up @@ -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";
Expand All @@ -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 {

Check warning on line 272 in svf/lib/SVFIR/SVFVariables.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/SVFIR/SVFVariables.cpp#L272

Added line #L272 was not covered by tests
std::string str;
std::stringstream rawstr(str);

Check warning on line 274 in svf/lib/SVFIR/SVFVariables.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/SVFIR/SVFVariables.cpp#L274

Added line #L274 was not covered by tests
rawstr << "GlobalValueObjNode ID: " << getId();
Expand Down

0 comments on commit c4a2cc0

Please sign in to comment.