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 120 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 462 of file CFLGraphBuilder.cpp.

463{
464 cflGraph->addCFLEdge(cflGraph->getGNode(src->getId()), cflGraph->getGNode(dst->getId()), kind);
465 std::string label = kindToLabelMap[kind];
466 label.append("bar");
467 cflGraph->addCFLEdge(cflGraph->getGNode(dst->getId()), cflGraph->getGNode(src->getId()), labelToKindMap[label]);
468 return;
469}
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:74

◆ addBiGepCFLEdge()

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

Adds bidirectional GEP edges with attributes.

Definition at line 471 of file CFLGraphBuilder.cpp.

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

◆ 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 280 of file CFLGraphBuilder.cpp.

281{
282 cflGraph = new CFLGraph(startKind);
283
284 buildlabelToKindMap(grammar);
285 for(auto it = graph->begin(); it!= graph->end(); it++)
286 {
287 CFLNode* node = new CFLNode((*it).first);
288 cflGraph->addCFLNode((*it).first, node);
289 }
290 for(auto it = graph->begin(); it!= graph->end(); it++)
291 {
292 ConstraintNode* node = (*it).second;
293 for(ConstraintEdge* edge : node->getOutEdges())
294 {
295 CFGrammar::Kind edgeLabel = edge->getEdgeKind();
296 // Need to get the offset from the Const Edge
297 // The offset present edge is only from Normal Gep CG at moment
299 {
300 NormalGepCGEdge *nGepEdge = SVFUtil::dyn_cast<NormalGepCGEdge>(edge);
301 CFGrammar::Attribute attr = nGepEdge->getConstantFieldIdx();
304 cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
305 std::string label = kindToLabelMap[edge->getEdgeKind()];
306 label.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
309 }
310 else
311 {
312 cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
313 std::string label = kindToLabelMap[edge->getEdgeKind()];
314 label.append("bar");
316 }
317 }
318 }
319 return cflGraph;
320}
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 322 of file CFLGraphBuilder.cpp.

323{
324 cflGraph = new CFLGraph(startKind);
325
326 buildlabelToKindMap(grammar);
327 for(auto it = graph->begin(); it!= graph->end(); it++)
328 {
329 CFLNode* node = new CFLNode((*it).first);
330 cflGraph->addCFLNode((*it).first, node);
331 }
332 for(auto it = graph->begin(); it!= graph->end(); it++)
333 {
334 ConstraintNode* node = (*it).second;
335 for(ConstraintEdge* edge : node->getOutEdges())
336 {
338 if (edge->getEdgeKind() == ConstraintEdge::Store)
339 {
340 if (pag->isNullPtr(edge->getSrcID()))
341 continue;
343 ConstraintNode* Dst = edge->getDstNode();
344 ConstraintNode* DerefNode = nullptr;
345 CFLNode* CFLDerefNode = nullptr;
346 for (ConstraintEdge* DstInEdge : Dst->getInEdges())
347 {
348 if (DstInEdge->getEdgeKind() == ConstraintEdge::Addr)
349 {
350 DerefNode = DstInEdge->getSrcNode();
351 CFLDerefNode = cflGraph->getGNode(DstInEdge->getSrcID());
352 break;
353 }
354 }
355 if (DerefNode == nullptr)
356 {
357
358 NodeID refId = pag->addDummyValNode();
359 CFLDerefNode = new CFLNode(refId);
364 label.append("bar");
366 }
370 label.append("bar");
372 }
374 else if ( edge->getEdgeKind() == ConstraintEdge::Load)
375 {
377 ConstraintNode* Src = edge->getSrcNode();
378 ConstraintNode* DerefNode = nullptr;
379 CFLNode* CFLDerefNode = nullptr;
380 for (ConstraintEdge* SrcInEdge : Src->getInEdges())
381 {
382 if (SrcInEdge->getEdgeKind() == ConstraintEdge::Addr)
383 {
384 DerefNode = SrcInEdge->getSrcNode();
385 CFLDerefNode = cflGraph->getGNode(SrcInEdge->getSrcID());
386 }
387 }
388 if (DerefNode == nullptr)
389 {
390 NodeID refId = pag->addDummyValNode();
391 CFLDerefNode = new CFLNode(refId);
396 label.append("bar");
398 }
402 label.append("bar");
404 }
405 else if ( edge->getEdgeKind() == ConstraintEdge::VariantGep)
406 {
411 connectVGep(cflGraph, graph, edge->getSrcNode(), edge->getDstNode(), 8, pag);
412 }
413 else
414 {
415 CFGrammar::Kind edgeLabel = edge->getEdgeKind();
416 // Need to get the offset from the Const Edge
417 // The offset present edge is only from Normal Gep CG at moment
419 {
420 NormalGepCGEdge *nGepEdge = SVFUtil::dyn_cast<NormalGepCGEdge>(edge);
421 CFGrammar::Attribute attr = nGepEdge->getConstantFieldIdx();
424 cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
425 std::string label = kindToLabelMap[edge->getEdgeKind()];
426 label.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
429 }
430 else
431 {
432 cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
433 std::string label = kindToLabelMap[edge->getEdgeKind()];
434 label.append("bar");
436 }
437 }
438 }
439 }
440 return cflGraph;
441}
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:55

◆ 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: