Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion svf-llvm/include/SVF-LLVM/ICFGBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class ICFGBuilder
inline void addGlobalICFGNode()
{
icfg->globalBlockNode = new GlobalICFGNode(icfg->totalICFGNode++);
icfg->addICFGNode(icfg->globalBlockNode);
icfg->addGlobalICFGNode(icfg->globalBlockNode);
}

private:
Expand Down
1 change: 1 addition & 0 deletions svf-llvm/include/SVF-LLVM/SVFIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace SVF
*/
class SVFIRBuilder: public llvm::InstVisitor<SVFIRBuilder>
{
friend class GraphDBSVFIRBuilder;

private:
SVFIR* pag;
Expand Down
13 changes: 4 additions & 9 deletions svf-llvm/lib/SVFIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,7 @@ SVFIR* SVFIRBuilder::build()
double startTime = SVFStat::getClk(true);

DBOUT(DGENERAL, outs() << pasMsg("\t Building SVFIR ...\n"));

// We read SVFIR from a user-defined txt instead of parsing SVFIR from LLVM IR
if (SVFIR::pagReadFromTXT())
{
PAGBuilderFromFile fileBuilder(SVFIR::pagFileName());
return fileBuilder.build();
}


// If the SVFIR has been built before, then we return the unique SVFIR of the program
if(pag->getNodeNumAfterPAGBuild() > 1)
return pag;
Expand Down Expand Up @@ -1597,7 +1590,9 @@ const Value* SVFIRBuilder::getBaseValueForExtArg(const Value* V)
void SVFIRBuilder::handleIndCall(CallBase* cs)
{
const CallICFGNode* cbn = llvmModuleSet()->getCallICFGNode(cs);
pag->addIndirectCallsites(cbn,llvmModuleSet()->getValueNode(cs->getCalledOperand()));
NodeID indFunPtrId = llvmModuleSet()->getValueNode(cs->getCalledOperand());
const_cast<CallICFGNode*>(cbn)->setIndFunPtr(pag->getGNode(indFunPtrId));
pag->addIndirectCallsites(cbn,indFunPtrId);
}

void SVFIRBuilder::updateCallGraph(CallGraph* callgraph)
Expand Down
19 changes: 17 additions & 2 deletions svf-llvm/tools/SABER/saber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,24 @@ int main(int argc, char ** argv)
argc, argv, "Source-Sink Bug Detector", "[options] <input-bitcode...>"
);

LLVMModuleSet::buildSVFModule(moduleNameVec);
SVFIRBuilder builder;
SVFIR* pag = builder.build();
SVFIR* pag;

if (Options::ReadFromDB())
{
pag = builder.build();
pag->setPagFromTXT("ReadFromDB");
}
else
{
if (Options::WriteAnder() == "ir_annotator")
{
LLVMModuleSet::preProcessBCs(moduleNameVec);
}

LLVMModuleSet::buildSVFModule(moduleNameVec);
pag = builder.build();
}


std::unique_ptr<LeakChecker> saber;
Expand Down
6 changes: 4 additions & 2 deletions svf-llvm/tools/WPA/wpa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ int main(int argc, char** argv)
// Refers to content of a singleton unique_ptr<SVFIR> in SVFIR.
SVFIR* pag;

if (Options::ReadJson())
if (Options::ReadFromDB())
{
assert(false && "please implement SVFIRReader::read");
SVFIRBuilder builder;
pag = builder.build();
pag->setPagFromTXT("ReadFromDB");
}
else
{
Expand Down
19 changes: 17 additions & 2 deletions svf/include/Graphs/BasicBlockG.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class SVFBasicBlock : public GenericBasicBlockNodeTy
friend class FunObjVar;
friend class ICFGBuilder;
friend class ICFG;
friend class GraphDBClient;

public:
typedef std::vector<const ICFGNode*>::const_iterator const_iterator;
Expand All @@ -98,6 +99,17 @@ class SVFBasicBlock : public GenericBasicBlockNodeTy

/// @}

// Getters of predecessor and successor basic blocks, used for writing bb to DB
const std::vector<const SVFBasicBlock*> getSuccBBs() const
{
return succBBs;
}

const std::vector<const SVFBasicBlock*> getPredBBs() const
{
return predBBs;
}

public:
/// Constructor without name
SVFBasicBlock(NodeID id, const FunObjVar* f): GenericBasicBlockNodeTy(id, BasicBlockKd), fun(f)
Expand Down Expand Up @@ -293,20 +305,23 @@ class BasicBlockGraph: public GenericBasicBlockGraphTy
NodeID id{0};
public:
/// Constructor
BasicBlockGraph()
BasicBlockGraph(): GenericBasicBlockGraphTy()
{

}


SVFBasicBlock* addBasicBlock(const std::string& bbname)
{
id++;
SVFBasicBlock* bb = new SVFBasicBlock(id, nullptr);
addGNode(id, bb);
bb->setName(bbname);
addBasicBlock(bb);
return bb;
}

void addBasicBlock(SVFBasicBlock* bb);

};
}

Expand Down
12 changes: 12 additions & 0 deletions svf/include/Graphs/CHG.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class CHEdge: public GenericCHEdgeTy
typedef GenericNode<CHNode, CHEdge> GenericCHNodeTy;
class CHNode: public GenericCHNodeTy
{
friend class GraphDBClient;

public:
typedef enum
Expand Down Expand Up @@ -222,13 +223,24 @@ class CHNode: public GenericCHNodeTy
* virtualFunctionVectors = {{Af1, Af2, ...}, {Bg1, Bg2, ...}}
*/
std::vector<FuncVector> virtualFunctionVectors;

protected:
inline size_t getFlags() const
{
return flags;
}
inline void setFlags(size_t f)
{
flags = f;
}
};

/// class hierarchy graph
typedef GenericGraph<CHNode, CHEdge> GenericCHGraphTy;
class CHGraph: public CommonCHGraph, public GenericCHGraphTy
{
friend class CHGBuilder;
friend class GraphDBClient;

public:
typedef Set<const CHNode*> CHNodeSetTy;
Expand Down
32 changes: 30 additions & 2 deletions svf/include/Graphs/CallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,20 @@ class CallGraphNode : public GenericPTACallGraphNodeTy
{
return node->getNodeKind() == CallNodeKd;
}

std::string sourceLocToDBString() const
{
std::string sourceLoc = "";
if (!getSourceLoc().empty())
{
sourceLoc = ", source_loc: '" + getSourceLoc() + "'";
}
else
{
sourceLoc = ", source_loc: ''";
}
return sourceLoc;
}
//@}
};

Expand All @@ -233,6 +247,8 @@ class CallGraphNode : public GenericPTACallGraphNodeTy
typedef GenericGraph<CallGraphNode, CallGraphEdge> GenericPTACallGraphTy;
class CallGraph : public GenericPTACallGraphTy
{
friend class GraphDBClient;


public:
typedef CallGraphEdge::CallGraphEdgeSet CallGraphEdgeSet;
Expand Down Expand Up @@ -281,20 +297,32 @@ class CallGraph : public GenericPTACallGraphTy
if(it == csToIdMap.end())
{
CallSiteID id = totalCallSiteNum++;
csToIdMap.insert(std::make_pair(newCS, id));
idToCSMap.insert(std::make_pair(id, newCS));
addCallSite(cs,callee,id);
return id;
}
return it->second;
}

CallSiteID addCallSite(const CallICFGNode* cs, const FunObjVar* callee, const CallSiteID csid);

/// Add call graph edge
inline void addEdge(CallGraphEdge* edge)
{
edge->getDstNode()->addIncomingEdge(edge);
edge->getSrcNode()->addOutgoingEdge(edge);
}

/// add direct call graph edge from database [only used this function when loading cgEdges from db results]
void addDirectCallGraphEdge(CallGraphEdge* cgEdge);

/// add call graph node from database [only used this function when loading cgNodes from db results]
void addCallGraphNode(CallGraphNode* cgNode);

/// Whether we have already created this call graph edge, only used when adding new edge from db query results
CallGraphEdge* hasGraphEdge(CallGraphEdge* cgEdge) const;

/// Add indirect call graph edge from database [only used this function when loading cgEdges from db results]
void addIndirectCallGraphEdge(CallGraphEdge* cgEdge);
public:
/// Constructor
CallGraph(CGEK k = NormCallGraph);
Expand Down
24 changes: 17 additions & 7 deletions svf/include/Graphs/ICFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ICFG : public GenericICFGTy
{
friend class ICFGBuilder;
friend class ICFGSimplification;
friend class GraphDBClient;

public:

Expand Down Expand Up @@ -198,23 +199,32 @@ class ICFG : public GenericICFGTy
virtual inline FunEntryICFGNode* addFunEntryICFGNode(const FunObjVar* svfFunc)
{
FunEntryICFGNode* sNode = new FunEntryICFGNode(totalICFGNode++,svfFunc);
addICFGNode(sNode);
return FunToFunEntryNodeMap[svfFunc] = sNode;
return addFunEntryICFGNode(sNode);
}

virtual inline FunEntryICFGNode* addFunEntryICFGNode(FunEntryICFGNode* funEntryICFGNode)
{
addICFGNode(funEntryICFGNode);
return FunToFunEntryNodeMap[funEntryICFGNode->getFun()] = funEntryICFGNode;
}

virtual void addGlobalICFGNode(GlobalICFGNode* globalICFGNode);

virtual inline FunExitICFGNode* addFunExitICFGNode(const FunObjVar* svfFunc)
{
FunExitICFGNode* sNode = new FunExitICFGNode(totalICFGNode++, svfFunc);
addICFGNode(sNode);
return FunToFunExitNodeMap[svfFunc] = sNode;
return addFunExitICFGNode(sNode);
}

/// Add a ICFG node
virtual inline void addICFGNode(ICFGNode* node)
virtual inline FunExitICFGNode* addFunExitICFGNode(FunExitICFGNode* funExitICFGNode)
{
addGNode(node->getId(),node);
addICFGNode(funExitICFGNode);
return FunToFunExitNodeMap[funExitICFGNode->getFun()] = funExitICFGNode;
}

/// Add a ICFG node
virtual void addICFGNode(ICFGNode* node);

public:
/// Get a basic block ICFGNode
/// TODO:: need to fix the assertions
Expand Down
1 change: 1 addition & 0 deletions svf/include/Graphs/ICFGEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class IntraCFGEdge : public ICFGEdge
{
friend class ICFG;
friend class SVFIRBuilder;
friend class GraphDBClient;

public:
/// Constructor
Expand Down
Loading
Loading