svf-lib 1.0.1682 → 1.0.1684

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -492,11 +492,12 @@ protected:
492
492
  NodeRefToCycleDepthNumber _nodeToCDN;
493
493
  CycleDepthNumber _num;
494
494
  CFBasicBlockNodes _stack;
495
+ CFBasicBlockGraph* _graph;
495
496
 
496
497
  public:
497
498
  explicit CFBasicBlockGWTO() : _num(0) {}
498
499
 
499
- explicit CFBasicBlockGWTO(const CFBasicBlockNode *entry) : _num(0)
500
+ explicit CFBasicBlockGWTO(CFBasicBlockGraph* graph, const CFBasicBlockNode *entry) : _num(0), _graph(graph)
500
501
  {
501
502
  build(entry);
502
503
  }
@@ -652,12 +653,13 @@ protected:
652
653
  const CFBasicBlockGWTOCycleDepth &_headWTOCycleDepth;
653
654
  const CFBasicBlockNode *_head;
654
655
  NodeRefToWTOCycleDepthPtr &_nodeToWTOCycleDepth;
656
+ CFBasicBlockGraph* _graph;
655
657
 
656
658
  public:
657
659
 
658
- explicit TailBuilder(NodeRefToWTOCycleDepthPtr &nodeToWTOCycleDepth, NodeRefSet &tails, const CFBasicBlockNode *head,
660
+ explicit TailBuilder(CFBasicBlockGraph* graph, NodeRefToWTOCycleDepthPtr &nodeToWTOCycleDepth, NodeRefSet &tails, const CFBasicBlockNode *head,
659
661
  const CFBasicBlockGWTOCycleDepth &headWTOCycleDepth) : _tails(tails), _headWTOCycleDepth(headWTOCycleDepth), _head(head), _nodeToWTOCycleDepth(
660
- nodeToWTOCycleDepth)
662
+ nodeToWTOCycleDepth), _graph(graph)
661
663
  {
662
664
  }
663
665
 
@@ -671,15 +673,27 @@ protected:
671
673
 
672
674
  virtual void visit(const CFBasicBlockGWTONode &node) override
673
675
  {
674
- for (const auto &edge: node.node()->getOutEdges())
676
+ if(const CallICFGNode* callNode = SVFUtil::dyn_cast<CallICFGNode>(node.node()->getICFGNodes().front()))
675
677
  {
676
- const CFBasicBlockNode *succ = edge->getDstNode();
678
+ const CFBasicBlockNode *succ = _graph->getCFBasicBlockNode(callNode->getRetICFGNode()->getId());
677
679
  const CFBasicBlockGWTOCycleDepth &succNesting = getWTOCycleDepth(succ);
678
680
  if (succ != _head && succNesting <= _headWTOCycleDepth)
679
681
  {
680
682
  _tails.insert(node.node());
681
683
  }
682
684
  }
685
+ else
686
+ {
687
+ for (const auto &edge: node.node()->getOutEdges())
688
+ {
689
+ const CFBasicBlockNode *succ = edge->getDstNode();
690
+ const CFBasicBlockGWTOCycleDepth &succNesting = getWTOCycleDepth(succ);
691
+ if (succ != _head && succNesting <= _headWTOCycleDepth)
692
+ {
693
+ _tails.insert(node.node());
694
+ }
695
+ }
696
+ }
683
697
  }
684
698
 
685
699
  protected:
@@ -751,14 +765,25 @@ protected:
751
765
  const CFBasicBlockGWTOCycle *component(const CFBasicBlockNode *node)
752
766
  {
753
767
  WTOCompRefList partition;
754
- for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
768
+ if (const CallICFGNode* callNode = SVFUtil::dyn_cast<CallICFGNode>(node->getICFGNodes().front()))
755
769
  {
756
- const CFBasicBlockNode *succ = (*it)->getDstNode();
770
+ const CFBasicBlockNode *succ = _graph->getCFBasicBlockNode(callNode->getRetICFGNode()->getId());
757
771
  if (getCDN(succ) == 0)
758
772
  {
759
773
  visit(succ, partition);
760
774
  }
761
775
  }
776
+ else
777
+ {
778
+ for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
779
+ {
780
+ const CFBasicBlockNode *succ = (*it)->getDstNode();
781
+ if (getCDN(succ) == 0)
782
+ {
783
+ visit(succ, partition);
784
+ }
785
+ }
786
+ }
762
787
  const CFBasicBlockGWTOCycle *ptr = newCycle(node, partition);
763
788
  _headToCycle.emplace(node, ptr);
764
789
  return ptr;
@@ -776,9 +801,9 @@ protected:
776
801
  head = _num;
777
802
  setCDN(node, head);
778
803
  loop = false;
779
- for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
804
+ if (const CallICFGNode* callNode = SVFUtil::dyn_cast<CallICFGNode>(node->getICFGNodes().front()))
780
805
  {
781
- const CFBasicBlockNode *succ = (*it)->getDstNode();
806
+ const CFBasicBlockNode *succ = _graph->getCFBasicBlockNode(callNode->getRetICFGNode()->getId());
782
807
  CycleDepthNumber succ_dfn = getCDN(succ);
783
808
  if (succ_dfn == CycleDepthNumber(0))
784
809
  {
@@ -794,6 +819,27 @@ protected:
794
819
  loop = true;
795
820
  }
796
821
  }
822
+ else
823
+ {
824
+ for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
825
+ {
826
+ const CFBasicBlockNode *succ = (*it)->getDstNode();
827
+ CycleDepthNumber succ_dfn = getCDN(succ);
828
+ if (succ_dfn == CycleDepthNumber(0))
829
+ {
830
+ min = visit(succ, partition);
831
+ }
832
+ else
833
+ {
834
+ min = succ_dfn;
835
+ }
836
+ if (min <= head)
837
+ {
838
+ head = min;
839
+ loop = true;
840
+ }
841
+ }
842
+ }
797
843
  if (head == getCDN(node))
798
844
  {
799
845
  setCDN(node, UINT_MAX);
@@ -831,7 +877,7 @@ protected:
831
877
  for (const auto &head: _headToCycle)
832
878
  {
833
879
  NodeRefSet tails;
834
- TailBuilder builder(_nodeToDepth, tails, head.first, getWTOCycleDepth(head.first));
880
+ TailBuilder builder(_graph, _nodeToDepth, tails, head.first, getWTOCycleDepth(head.first));
835
881
  for (auto it = head.second->begin(), eit = head.second->end(); it != eit; ++it)
836
882
  {
837
883
  (*it)->accept(&builder);
@@ -127,8 +127,6 @@ public:
127
127
  {
128
128
  }
129
129
 
130
- CFBasicBlockNode(const SVFBasicBlock* bb);
131
-
132
130
  friend std::ostream &operator<<(std::ostream &o, const CFBasicBlockNode &node)
133
131
  {
134
132
  o << node.toString();
@@ -143,10 +141,9 @@ public:
143
141
  return (*_icfgNodes.begin())->getBB()->getName();
144
142
  }
145
143
 
146
- inline const SVFBasicBlock *getSVFBasicBlock() const
144
+ inline const std::vector<const ICFGNode*>& getICFGNodes() const
147
145
  {
148
- assert(!_icfgNodes.empty() && "no ICFG nodes in CFBB");
149
- return (*_icfgNodes.begin())->getBB();
146
+ return _icfgNodes;
150
147
  }
151
148
 
152
149
  inline const SVFFunction *getFunction() const
@@ -355,7 +352,6 @@ class CFBasicBlockGraph : public GenericCFBasicBlockGTy
355
352
  private:
356
353
  u32_t _totalCFBasicBlockNode{0};
357
354
  u32_t _totalCFBasicBlockEdge{0};
358
- Map<const SVFFunction*, CFBasicBlockNode*> _funToFirstNode;
359
355
  public:
360
356
 
361
357
  CFBasicBlockGraph() = default;
@@ -379,27 +375,6 @@ public:
379
375
  return hasGNode(id);
380
376
  }
381
377
 
382
- inline CFBasicBlockNode* getFirstCFBasicBlockNode(const SVFFunction* fun) const
383
- {
384
- if (fun && _funToFirstNode.find(fun) != _funToFirstNode.end())
385
- {
386
- return _funToFirstNode.at(fun);
387
- }
388
- else
389
- {
390
- return nullptr;
391
- }
392
- }
393
- inline bool hasFirstCFBasicBlockNode(const SVFFunction* fun) const
394
- {
395
- return fun && _funToFirstNode.find(fun) != _funToFirstNode.end();
396
- }
397
-
398
- inline void setFirstCFBasicBlockNode(const Map<const SVFFunction*, CFBasicBlockNode*>& svfNodeMap)
399
- {
400
- _funToFirstNode = svfNodeMap;
401
- }
402
-
403
378
 
404
379
  bool hasCFBasicBlockEdge(CFBasicBlockNode *src, CFBasicBlockNode *dst, ICFGEdge *icfgEdge)
405
380
  {
@@ -490,24 +465,6 @@ public:
490
465
  }
491
466
  };
492
467
 
493
- class CFBasicBlockGBuilder
494
- {
495
-
496
- private:
497
- CFBasicBlockGraph* _CFBasicBlockG;
498
-
499
- public:
500
- CFBasicBlockGBuilder() : _CFBasicBlockG() {}
501
-
502
- virtual void build(SVFModule* module);
503
-
504
- virtual void build(ICFG* icfg);
505
-
506
- inline CFBasicBlockGraph* getCFBasicBlockGraph()
507
- {
508
- return _CFBasicBlockG;
509
- }
510
- };
511
468
  }
512
469
 
513
470
 
@@ -537,6 +494,10 @@ struct GenericGraphTraits<SVF::CFBasicBlockGraph *>
537
494
  typedef SVF::CFBasicBlockNode *NodeRef;
538
495
  };
539
496
 
497
+ } // End namespace SVF
498
+
499
+ namespace SVF
500
+ {
540
501
  template<>
541
502
  struct DOTGraphTraits<SVF::CFBasicBlockGraph *> : public DOTGraphTraits<SVF::SVFIR *>
542
503
  {
@@ -574,22 +535,73 @@ struct DOTGraphTraits<SVF::CFBasicBlockGraph *> : public DOTGraphTraits<SVF::SVF
574
535
  {
575
536
  std::string str;
576
537
  std::stringstream rawstr(str);
577
- rawstr << "color=black";
538
+ if(node->getICFGNodes().size() == 1)
539
+ {
540
+ const ICFGNode* n = node->getICFGNodes()[0];
541
+ if(SVFUtil::isa<IntraICFGNode>(n))
542
+ {
543
+ rawstr << "color=black";
544
+ }
545
+ else if(SVFUtil::isa<FunEntryICFGNode>(n))
546
+ {
547
+ rawstr << "color=yellow";
548
+ }
549
+ else if(SVFUtil::isa<FunExitICFGNode>(n))
550
+ {
551
+ rawstr << "color=green";
552
+ }
553
+ else if(SVFUtil::isa<CallICFGNode>(n))
554
+ {
555
+ rawstr << "color=red";
556
+ }
557
+ else if(SVFUtil::isa<RetICFGNode>(n))
558
+ {
559
+ rawstr << "color=blue";
560
+ }
561
+ else if(SVFUtil::isa<GlobalICFGNode>(n))
562
+ {
563
+ rawstr << "color=purple";
564
+ }
565
+ else
566
+ assert(false && "no such kind of node!!");
567
+ }
568
+ else
569
+ {
570
+ rawstr << "color=black";
571
+ }
572
+ rawstr << "";
578
573
  return rawstr.str();
579
574
  }
580
575
 
581
576
  template<class EdgeIter>
582
577
  static std::string getEdgeAttributes(NodeType *, EdgeIter EI, SVF::CFBasicBlockGraph *)
583
578
  {
584
- return "style=solid";
579
+ CFBasicBlockEdge* edge = *(EI.getCurrent());
580
+ assert(edge && "No edge found!!");
581
+ if (SVFUtil::isa<CallCFGEdge>(edge->getICFGEdge()))
582
+ return "style=solid,color=red";
583
+ else if (SVFUtil::isa<RetCFGEdge>(edge->getICFGEdge()))
584
+ return "style=solid,color=blue";
585
+ else
586
+ return "style=solid";
587
+ return "";
585
588
  }
586
589
 
587
590
  template<class EdgeIter>
588
591
  static std::string getEdgeSourceLabel(NodeType *, EdgeIter EI)
589
592
  {
590
- return "";
593
+ CFBasicBlockEdge* edge = *(EI.getCurrent());
594
+ assert(edge && "No edge found!!");
595
+
596
+ std::string str;
597
+ std::stringstream rawstr(str);
598
+ if (const CallCFGEdge* dirCall = SVFUtil::dyn_cast<CallCFGEdge>(edge->getICFGEdge()))
599
+ rawstr << dirCall->getCallSite();
600
+ else if (const RetCFGEdge* dirRet = SVFUtil::dyn_cast<RetCFGEdge>(edge->getICFGEdge()))
601
+ rawstr << dirRet->getCallSite();
602
+
603
+ return rawstr.str();
591
604
  }
592
605
  };
593
-
594
- } // End namespace SVF
606
+ }
595
607
  #endif //SVF_CFBASICBLOCKG_H
@@ -0,0 +1,59 @@
1
+ //===- CFBasicBlockGBuilder.h ----------------------------------------------------------------//
2
+ //
3
+ // SVF: Static Value-Flow Analysis
4
+ //
5
+ // Copyright (C) <2013-> <Yulei Sui>
6
+ //
7
+
8
+ // This program is free software: you can redistribute it and/or modify
9
+ // it under the terms of the GNU Affero General Public License as published by
10
+ // the Free Software Foundation, either version 3 of the License, or
11
+ // (at your option) any later version.
12
+
13
+ // This program is distributed in the hope that it will be useful,
14
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ // GNU Affero General Public License for more details.
17
+
18
+ // You should have received a copy of the GNU Affero General Public License
19
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ //
21
+ //===----------------------------------------------------------------------===//
22
+
23
+ /*
24
+ * CFBasicBlockGBuilder.h
25
+ *
26
+ * Created on: 17 Oct. 2023
27
+ * Author: Xiao, Jiawei
28
+ */
29
+
30
+ #include "Graphs/CFBasicBlockG.h"
31
+
32
+ namespace SVF
33
+ {
34
+
35
+ class CFBasicBlockGBuilder
36
+ {
37
+
38
+ private:
39
+ CFBasicBlockGraph* _CFBasicBlockG;
40
+
41
+ public:
42
+ CFBasicBlockGBuilder() : _CFBasicBlockG() {}
43
+
44
+ virtual void build(ICFG* icfg);
45
+
46
+ inline CFBasicBlockGraph* getCFBasicBlockGraph()
47
+ {
48
+ return _CFBasicBlockG;
49
+ }
50
+ private:
51
+ void initCFBasicBlockGNodes(ICFG *icfg, Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes);
52
+
53
+ void addInterBBEdge(ICFG *icfg, Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes);
54
+
55
+ void addIntraBBEdge(ICFG *icfg, Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes);
56
+
57
+ void addInterProceduralEdge(ICFG *icfg, Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes);
58
+ };
59
+ }
@@ -84,7 +84,10 @@ public:
84
84
 
85
85
  virtual const std::string toString() const
86
86
  {
87
- return _icfgEdge->toString();
87
+ std::string str;
88
+ std::stringstream rawstr(str);
89
+ rawstr << "CFBBGEdge: [CFBBGNode" << getDstID() << " <-- CFBBGNode" << getSrcID() << "]\t";
90
+ return rawstr.str();
88
91
  }
89
92
 
90
93
  inline const ICFGEdge *getICFGEdge() const
@@ -575,13 +578,21 @@ struct DOTGraphTraits<SVF::CFBasicBlockGraph *> : public DOTGraphTraits<SVF::SVF
575
578
  {
576
579
  CFBasicBlockEdge* edge = *(EI.getCurrent());
577
580
  assert(edge && "No edge found!!");
578
- if (SVFUtil::isa<CallCFGEdge>(edge->getICFGEdge()))
579
- return "style=solid,color=red";
580
- else if (SVFUtil::isa<RetCFGEdge>(edge->getICFGEdge()))
581
- return "style=solid,color=blue";
581
+ if (edge->getICFGEdge())
582
+ {
583
+ if (SVFUtil::isa<CallCFGEdge>(edge->getICFGEdge()))
584
+ {
585
+ return "style=solid,color=red";
586
+ }
587
+ else if (SVFUtil::isa<RetCFGEdge>(edge->getICFGEdge()))
588
+ return "style=solid,color=blue";
589
+ else
590
+ return "style=solid";
591
+ }
582
592
  else
593
+ {
583
594
  return "style=solid";
584
- return "";
595
+ }
585
596
  }
586
597
 
587
598
  template<class EdgeIter>
@@ -592,11 +603,13 @@ struct DOTGraphTraits<SVF::CFBasicBlockGraph *> : public DOTGraphTraits<SVF::SVF
592
603
 
593
604
  std::string str;
594
605
  std::stringstream rawstr(str);
595
- if (const CallCFGEdge* dirCall = SVFUtil::dyn_cast<CallCFGEdge>(edge->getICFGEdge()))
596
- rawstr << dirCall->getCallSite();
597
- else if (const RetCFGEdge* dirRet = SVFUtil::dyn_cast<RetCFGEdge>(edge->getICFGEdge()))
598
- rawstr << dirRet->getCallSite();
599
-
606
+ if (edge->getICFGEdge())
607
+ {
608
+ if (const CallCFGEdge* dirCall = SVFUtil::dyn_cast<CallCFGEdge>(edge->getICFGEdge()))
609
+ rawstr << dirCall->getCallSite();
610
+ else if (const RetCFGEdge* dirRet = SVFUtil::dyn_cast<RetCFGEdge>(edge->getICFGEdge()))
611
+ rawstr << dirRet->getCallSite();
612
+ }
600
613
  return rawstr.str();
601
614
  }
602
615
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-lib",
3
- "version": "1.0.1682",
3
+ "version": "1.0.1684",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {