Static Value-Flow Analysis
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. More...
 
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. More...
 
Map< std::string, Kind > & getLabelToKindMap ()
 Returns a reference to the map that associates string labels with their corresponding Kind. More...
 
Map< Kind, std::string > & getKindToLabelMap ()
 Returns a reference to the map that associates Kinds with their corresponding string labels. More...
 
Map< CFGrammar::Kind, Set< CFGrammar::Attribute > > & getKindToAttrsMap ()
 Returns a reference to the map that associates Kinds with their corresponding attributes. More...
 

Private Member Functions

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

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. More...
 
void buildlabelToKindMap (GrammarBase *grammar)
 build label and kind connect from the grammar More...
 
CFLNodeaddGNode (u32_t NodeID)
 add src and dst node from file More...
 
CFLGraphbuildFromText (std::string fileName, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
 Method to build a CFL graph from a Text file. More...
 
CFLGraphbuildFromDot (std::string filename, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
 Method to build a CFL graph from a Dot file. More...
 
CFLGraphbuildFromJson (std::string filename, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
 Method to build a CFL graph from a Json file. More...
 
- Protected Attributes inherited from SVF::CFLGraphBuilder
Map< std::string, KindlabelToKindMap
 Maps to maintain mapping between labels and kinds. More...
 
Map< Kind, std::stringkindToLabelMap
 
Map< CFGrammar::Kind, Set< CFGrammar::Attribute > > kindToAttrsMap
 Map to maintain attributes associated with each kind. More...
 
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 433 of file CFLGraphBuilder.cpp.

434 {
435  cflGraph->addCFLEdge(cflGraph->getGNode(src->getId()), cflGraph->getGNode(dst->getId()), kind);
436  std::string label = kindToLabelMap[kind];
437  label.append("bar");
438  cflGraph->addCFLEdge(cflGraph->getGNode(dst->getId()), cflGraph->getGNode(src->getId()), labelToKindMap[label]);
439  return;
440 }
const char *const string
Definition: cJSON.h:172
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.
Definition: GenericGraph.h:653

◆ addBiGepCFLEdge()

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

Adds bidirectional GEP edges with attributes.

Definition at line 442 of file CFLGraphBuilder.cpp.

443 {
445  cflGraph->addCFLEdge(cflGraph->getGNode(src->getId()), cflGraph->getGNode(dst->getId()), edgeLabel);
447  label.append("bar");
448  cflGraph->addCFLEdge(cflGraph->getGNode(dst->getId()), cflGraph->getGNode(src->getId()), CFGrammar::getAttributedKind(attri, labelToKindMap[label]));
449  return;
450 }
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 251 of file CFLGraphBuilder.cpp.

252 {
253  cflGraph = new CFLGraph(startKind);
254 
255  buildlabelToKindMap(grammar);
256  for(auto it = graph->begin(); it!= graph->end(); it++)
257  {
258  CFLNode* node = new CFLNode((*it).first);
259  cflGraph->addCFLNode((*it).first, node);
260  }
261  for(auto it = graph->begin(); it!= graph->end(); it++)
262  {
263  ConstraintNode* node = (*it).second;
264  for(ConstraintEdge* edge : node->getOutEdges())
265  {
266  CFGrammar::Kind edgeLabel = edge->getEdgeKind();
267  // Need to get the offset from the Const Edge
268  // The offset present edge is only from Normal Gep CG at moment
269  if(NormalGepCGEdge::classof(edge))
270  {
271  NormalGepCGEdge *nGepEdge = SVFUtil::dyn_cast<NormalGepCGEdge>(edge);
272  CFGrammar::Attribute attr = nGepEdge->getConstantFieldIdx();
273  addAttribute(edgeLabel, attr);
274  edgeLabel = CFGrammar::getAttributedKind(attr, edgeLabel);
275  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
276  std::string label = kindToLabelMap[edge->getEdgeKind()];
277  label.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
278  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFGrammar::getAttributedKind(attr, labelToKindMap[label]));
279  addAttribute(labelToKindMap[label], attr);
280  }
281  else
282  {
283  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
284  std::string label = kindToLabelMap[edge->getEdgeKind()];
285  label.append("bar");
286  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), labelToKindMap[label]);
287  }
288  }
289  }
290  return cflGraph;
291 }
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 293 of file CFLGraphBuilder.cpp.

294 {
295  cflGraph = new CFLGraph(startKind);
296 
297  buildlabelToKindMap(grammar);
298  for(auto it = graph->begin(); it!= graph->end(); it++)
299  {
300  CFLNode* node = new CFLNode((*it).first);
301  cflGraph->addCFLNode((*it).first, node);
302  }
303  for(auto it = graph->begin(); it!= graph->end(); it++)
304  {
305  ConstraintNode* node = (*it).second;
306  for(ConstraintEdge* edge : node->getOutEdges())
307  {
309  if (edge->getEdgeKind() == ConstraintEdge::Store)
310  {
311  if (pag->isNullPtr(edge->getSrcID()))
312  continue;
314  ConstraintNode* Dst = edge->getDstNode();
315  ConstraintNode* DerefNode = nullptr;
316  CFLNode* CFLDerefNode = nullptr;
317  for (ConstraintEdge* DstInEdge : Dst->getInEdges())
318  {
319  if (DstInEdge->getEdgeKind() == ConstraintEdge::Addr)
320  {
321  DerefNode = DstInEdge->getSrcNode();
322  CFLDerefNode = cflGraph->getGNode(DstInEdge->getSrcID());
323  break;
324  }
325  }
326  if (DerefNode == nullptr)
327  {
328 
329  NodeID refId = pag->addDummyValNode();
330  CFLDerefNode = new CFLNode(refId);
331  cflGraph->addCFLNode(refId, CFLDerefNode);
333  cflGraph->addCFLEdge(CFLDerefNode, cflGraph->getGNode(edge->getDstID()), ConstraintEdge::Addr);
335  label.append("bar");
336  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), CFLDerefNode, labelToKindMap[label]);
337  }
339  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(CFLDerefNode->getId()), ConstraintEdge::Copy);
341  label.append("bar");
342  cflGraph->addCFLEdge(cflGraph->getGNode(CFLDerefNode->getId()), cflGraph->getGNode(edge->getSrcID()), labelToKindMap[label]);
343  }
345  else if ( edge->getEdgeKind() == ConstraintEdge::Load)
346  {
348  ConstraintNode* Src = edge->getSrcNode();
349  ConstraintNode* DerefNode = nullptr;
350  CFLNode* CFLDerefNode = nullptr;
351  for (ConstraintEdge* SrcInEdge : Src->getInEdges())
352  {
353  if (SrcInEdge->getEdgeKind() == ConstraintEdge::Addr)
354  {
355  DerefNode = SrcInEdge->getSrcNode();
356  CFLDerefNode = cflGraph->getGNode(SrcInEdge->getSrcID());
357  }
358  }
359  if (DerefNode == nullptr)
360  {
361  NodeID refId = pag->addDummyValNode();
362  CFLDerefNode = new CFLNode(refId);
363  cflGraph->addCFLNode(refId, CFLDerefNode);
365  cflGraph->addCFLEdge(CFLDerefNode, cflGraph->getGNode(edge->getSrcID()), ConstraintEdge::Addr);
367  label.append("bar");
368  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), CFLDerefNode, labelToKindMap[label]);
369  }
371  cflGraph->addCFLEdge(cflGraph->getGNode(CFLDerefNode->getId()), cflGraph->getGNode(edge->getDstID()), ConstraintEdge::Copy);
373  label.append("bar");
374  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(CFLDerefNode->getId()), labelToKindMap[label]);
375  }
376  else if ( edge->getEdgeKind() == ConstraintEdge::VariantGep)
377  {
382  connectVGep(cflGraph, graph, edge->getSrcNode(), edge->getDstNode(), 8, pag);
383  }
384  else
385  {
386  CFGrammar::Kind edgeLabel = edge->getEdgeKind();
387  // Need to get the offset from the Const Edge
388  // The offset present edge is only from Normal Gep CG at moment
389  if(NormalGepCGEdge::classof(edge))
390  {
391  NormalGepCGEdge *nGepEdge = SVFUtil::dyn_cast<NormalGepCGEdge>(edge);
392  CFGrammar::Attribute attr = nGepEdge->getConstantFieldIdx();
393  addAttribute(edgeLabel, attr);
394  edgeLabel = CFGrammar::getAttributedKind(attr, edgeLabel);
395  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
396  std::string label = kindToLabelMap[edge->getEdgeKind()];
397  label.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
398  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFGrammar::getAttributedKind(attr, labelToKindMap[label]));
399  addAttribute(labelToKindMap[label], attr);
400  }
401  else
402  {
403  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
404  std::string label = kindToLabelMap[edge->getEdgeKind()];
405  label.append("bar");
406  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), labelToKindMap[label]);
407  }
408  }
409  }
410  }
411  return cflGraph;
412 }
void connectVGep(CFLGraph *cflGraph, ConstraintGraph *graph, ConstraintNode *src, ConstraintNode *dst, u32_t level, SVFIR *pag)
Connects VGep (Variable GEP)
NodeType * getSrcNode() const
Definition: GenericGraph.h:97
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: