Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
SVF::AliasCFLGraphBuilder Class Reference

AliasCFLGraphBuilder: a CFLGraphBuilder specialized for handling aliasing. More...

#include <CFLGraphBuilder.h>

Inheritance diagram for SVF::AliasCFLGraphBuilder:
SVF::CFLGraphBuilder

Public Member Functions

CFLGraphbuildBigraph (ConstraintGraph *graph, Kind startKind, GrammarBase *grammar)
 Builds a bidirectional CFL graph by copying nodes and edges from a const graph that inherits from GenericGraph.
 
CFLGraphbuildBiPEGgraph (ConstraintGraph *graph, Kind startKind, GrammarBase *grammar, SVFIR *pag)
 
- Public Member Functions inherited from SVF::CFLGraphBuilder
template<class N , class E >
CFLGraphbuild (GenericGraph< N, E > *graph, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
 
CFLGraphbuild (std::string fileName, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
 Method to build a CFL graph from external file.
 
Map< std::string, Kind > & getLabelToKindMap ()
 Returns a reference to the map that associates string labels with their corresponding Kind.
 
Map< Kind, std::string > & getKindToLabelMap ()
 Returns a reference to the map that associates Kinds with their corresponding string labels.
 
Map< CFGrammar::Kind, Set< CFGrammar::Attribute > > & getKindToAttrsMap ()
 Returns a reference to the map that associates Kinds with their corresponding attributes.
 

Private Member Functions

void connectVGep (CFLGraph *cflGraph, ConstraintGraph *graph, ConstraintNode *src, ConstraintNode *dst, u32_t level, SVFIR *pag)
 Connects VGep (Variable GEP)
 
void addBiCFLEdge (CFLGraph *cflGraph, ConstraintNode *src, ConstraintNode *dst, CFGrammar::Kind label)
 Handles edges, with the exception of the GEP.
 
void addBiGepCFLEdge (CFLGraph *cflGraph, ConstraintNode *src, ConstraintNode *dst, CFGrammar::Attribute attri)
 Adds bidirectional GEP edges with attributes.
 

Additional Inherited Members

- Protected Types inherited from SVF::CFLGraphBuilder
typedef CFGrammar::Kind Kind
 
typedef CFGrammar::Symbol Symbol
 
- Protected Member Functions inherited from SVF::CFLGraphBuilder
void addAttribute (CFGrammar::Kind kind, CFGrammar::Attribute attribute)
 Method to add an attribute to a specific kind.
 
void buildlabelToKindMap (GrammarBase *grammar)
 build label and kind connect from the grammar
 
CFLNodeaddGNode (u32_t NodeID)
 add src and dst node from file
 
CFLGraphbuildFromText (std::string fileName, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
 Method to build a CFL graph from a Text file.
 
CFLGraphbuildFromDot (std::string filename, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
 Method to build a CFL graph from a Dot file.
 
CFLGraphbuildFromJson (std::string filename, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
 Method to build a CFL graph from a Json file.
 
- Protected Attributes inherited from SVF::CFLGraphBuilder
Map< std::string, KindlabelToKindMap
 Maps to maintain mapping between labels and kinds.
 
Map< Kind, std::string > kindToLabelMap
 
Map< CFGrammar::Kind, Set< CFGrammar::Attribute > > kindToAttrsMap
 Map to maintain attributes associated with each kind.
 
Kind current
 
CFLGraphcflGraph
 

Detailed Description

AliasCFLGraphBuilder: a CFLGraphBuilder specialized for handling aliasing.

Definition at line 121 of file CFLGraphBuilder.h.

Member Function Documentation

◆ addBiCFLEdge()

void SVF::AliasCFLGraphBuilder::addBiCFLEdge ( CFLGraph cflGraph,
ConstraintNode src,
ConstraintNode dst,
CFGrammar::Kind  label 
)
private

Handles edges, with the exception of the GEP.

Definition at line 460 of file CFLGraphBuilder.cpp.

461{
462 cflGraph->addCFLEdge(cflGraph->getGNode(src->getId()), cflGraph->getGNode(dst->getId()), kind);
463 std::string label = kindToLabelMap[kind];
464 label.append("bar");
465 cflGraph->addCFLEdge(cflGraph->getGNode(dst->getId()), cflGraph->getGNode(src->getId()), labelToKindMap[label]);
466 return;
467}
Map< std::string, Kind > labelToKindMap
Maps to maintain mapping between labels and kinds.
Map< Kind, std::string > kindToLabelMap
virtual const CFLEdge * addCFLEdge(CFLNode *src, CFLNode *dst, CFLEdge::GEdgeFlag label)
Definition CFLGraph.cpp:47
NodeType * getGNode(NodeID id) const
Get a node.
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

◆ addBiGepCFLEdge()

void SVF::AliasCFLGraphBuilder::addBiGepCFLEdge ( CFLGraph cflGraph,
ConstraintNode src,
ConstraintNode dst,
CFGrammar::Attribute  attri 
)
private

Adds bidirectional GEP edges with attributes.

Definition at line 469 of file CFLGraphBuilder.cpp.

470{
472 cflGraph->addCFLEdge(cflGraph->getGNode(src->getId()), cflGraph->getGNode(dst->getId()), edgeLabel);
474 label.append("bar");
476 return;
477}
static Kind getAttributedKind(Attribute attribute, Kind kind)
Definition CFGrammar.h:269

◆ buildBigraph()

CFLGraph * SVF::AliasCFLGraphBuilder::buildBigraph ( ConstraintGraph graph,
Kind  startKind,
GrammarBase grammar 
)

Builds a bidirectional CFL graph by copying nodes and edges from a const graph that inherits from GenericGraph.

Definition at line 279 of file CFLGraphBuilder.cpp.

280{
281 cflGraph = new CFLGraph(startKind);
282
283 buildlabelToKindMap(grammar);
284 for(auto it = graph->begin(); it!= graph->end(); it++)
285 {
286 CFLNode* node = new CFLNode((*it).first);
287 cflGraph->addCFLNode((*it).first, node);
288 }
289 for(auto it = graph->begin(); it!= graph->end(); it++)
290 {
291 ConstraintNode* node = (*it).second;
292 for(ConstraintEdge* edge : node->getOutEdges())
293 {
294 CFGrammar::Kind edgeLabel = edge->getEdgeKind();
295 // Need to get the offset from the Const Edge
296 // The offset present edge is only from Normal Gep CG at moment
298 {
299 NormalGepCGEdge *nGepEdge = SVFUtil::dyn_cast<NormalGepCGEdge>(edge);
300 CFGrammar::Attribute attr = nGepEdge->getConstantFieldIdx();
303 cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
304 std::string label = kindToLabelMap[edge->getEdgeKind()];
305 label.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
308 }
309 else
310 {
311 cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
312 std::string label = kindToLabelMap[edge->getEdgeKind()];
313 label.append("bar");
315 }
316 }
317 }
318 return cflGraph;
319}
void buildlabelToKindMap(GrammarBase *grammar)
build label and kind connect from the grammar
void addAttribute(CFGrammar::Kind kind, CFGrammar::Attribute attribute)
Method to add an attribute to a specific kind.
virtual void addCFLNode(NodeID id, CFLNode *node)
Definition CFLGraph.cpp:42
static bool classof(const NormalGepCGEdge *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ConsGEdge.h:277

◆ buildBiPEGgraph()

CFLGraph * SVF::AliasCFLGraphBuilder::buildBiPEGgraph ( ConstraintGraph graph,
Kind  startKind,
GrammarBase grammar,
SVFIR pag 
)

Builds a bidirectional CFL graph by copying nodes and edges from any graph that inherits from GenericGraph Transfers Load and Store to copy edge and address edge to construct PEG style CFLGraph

Process Store

Check Dst of Store Dereference Node

Add Addr Edge

Add Copy Edge

Process Load

Check Src of Load Dereference Node

Add Addr Edge

Add Copy Edge

Handle VGep normalize to Normal Gep by connecting all geps' srcs to vgep dest Example: In Test Case: Ctest field-ptr-arith-varIdx.c.bc BFS Search the 8 LEVEL up to find the ValueNode, and the number of level search is arbitrary the more the level search the more valueNode and the Vgep Dst will possibly connect

Definition at line 321 of file CFLGraphBuilder.cpp.

322{
323 cflGraph = new CFLGraph(startKind);
324
325 buildlabelToKindMap(grammar);
326 for(auto it = graph->begin(); it!= graph->end(); it++)
327 {
328 CFLNode* node = new CFLNode((*it).first);
329 cflGraph->addCFLNode((*it).first, node);
330 }
331 for(auto it = graph->begin(); it!= graph->end(); it++)
332 {
333 ConstraintNode* node = (*it).second;
334 for(ConstraintEdge* edge : node->getOutEdges())
335 {
337 if (edge->getEdgeKind() == ConstraintEdge::Store)
338 {
339 if (pag->isNullPtr(edge->getSrcID()))
340 continue;
342 ConstraintNode* Dst = edge->getDstNode();
343 ConstraintNode* DerefNode = nullptr;
344 CFLNode* CFLDerefNode = nullptr;
345 for (ConstraintEdge* DstInEdge : Dst->getInEdges())
346 {
347 if (DstInEdge->getEdgeKind() == ConstraintEdge::Addr)
348 {
349 DerefNode = DstInEdge->getSrcNode();
350 CFLDerefNode = cflGraph->getGNode(DstInEdge->getSrcID());
351 break;
352 }
353 }
354 if (DerefNode == nullptr)
355 {
356 NodeID refId = pag->addDummyValNode();
357 CFLDerefNode = new CFLNode(refId);
362 label.append("bar");
364 }
368 label.append("bar");
370 }
372 else if ( edge->getEdgeKind() == ConstraintEdge::Load)
373 {
375 ConstraintNode* Src = edge->getSrcNode();
376 ConstraintNode* DerefNode = nullptr;
377 CFLNode* CFLDerefNode = nullptr;
378 for (ConstraintEdge* SrcInEdge : Src->getInEdges())
379 {
380 if (SrcInEdge->getEdgeKind() == ConstraintEdge::Addr)
381 {
382 DerefNode = SrcInEdge->getSrcNode();
383 CFLDerefNode = cflGraph->getGNode(SrcInEdge->getSrcID());
384 }
385 }
386 if (DerefNode == nullptr)
387 {
388 NodeID refId = pag->addDummyValNode();
389 CFLDerefNode = new CFLNode(refId);
394 label.append("bar");
396 }
400 label.append("bar");
402 }
403 else if ( edge->getEdgeKind() == ConstraintEdge::VariantGep)
404 {
409 connectVGep(cflGraph, graph, edge->getSrcNode(), edge->getDstNode(), 8, pag);
410 }
411 else
412 {
413 CFGrammar::Kind edgeLabel = edge->getEdgeKind();
414 // Need to get the offset from the Const Edge
415 // The offset present edge is only from Normal Gep CG at moment
417 {
418 NormalGepCGEdge *nGepEdge = SVFUtil::dyn_cast<NormalGepCGEdge>(edge);
419 CFGrammar::Attribute attr = nGepEdge->getConstantFieldIdx();
422 cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
423 std::string label = kindToLabelMap[edge->getEdgeKind()];
424 label.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
427 }
428 else
429 {
430 cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
431 std::string label = kindToLabelMap[edge->getEdgeKind()];
432 label.append("bar");
434 }
435 }
436 }
437 }
438 return cflGraph;
439}
void connectVGep(CFLGraph *cflGraph, ConstraintGraph *graph, ConstraintNode *src, ConstraintNode *dst, u32_t level, SVFIR *pag)
Connects VGep (Variable GEP)
NodeType * getSrcNode() const
u32_t NodeID
Definition GeneralType.h:76

◆ connectVGep()

void SVF::AliasCFLGraphBuilder::connectVGep ( CFLGraph cflGraph,
ConstraintGraph graph,
ConstraintNode src,
ConstraintNode dst,
u32_t  level,
SVFIR pag 
)
private

Connects VGep (Variable GEP)


The documentation for this class was generated from the following files: