svf-lib 1.0.1680 → 1.0.1682

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.
@@ -488,11 +488,12 @@ protected:
488
488
  NodeRefToCycleDepthNumber _nodeToCDN;
489
489
  CycleDepthNumber _num;
490
490
  CFBasicBlockNodes _stack;
491
+ CFBasicBlockGraph* _graph;
491
492
 
492
493
  public:
493
494
  explicit CFBasicBlockGWTO() : _num(0) {}
494
495
 
495
- explicit CFBasicBlockGWTO(const CFBasicBlockNode *entry) : _num(0)
496
+ explicit CFBasicBlockGWTO(CFBasicBlockGraph* graph, const CFBasicBlockNode *entry) : _num(0), _graph(graph)
496
497
  {
497
498
  build(entry);
498
499
  }
@@ -647,12 +648,13 @@ protected:
647
648
  const CFBasicBlockGWTOCycleDepth &_headWTOCycleDepth;
648
649
  const CFBasicBlockNode *_head;
649
650
  NodeRefToWTOCycleDepthPtr &_nodeToWTOCycleDepth;
651
+ CFBasicBlockGraph* _graph;
650
652
 
651
653
  public:
652
654
 
653
- explicit TailBuilder(NodeRefToWTOCycleDepthPtr &nodeToWTOCycleDepth, NodeRefSet &tails, const CFBasicBlockNode *head,
655
+ explicit TailBuilder(CFBasicBlockGraph* graph, NodeRefToWTOCycleDepthPtr &nodeToWTOCycleDepth, NodeRefSet &tails, const CFBasicBlockNode *head,
654
656
  const CFBasicBlockGWTOCycleDepth &headWTOCycleDepth) : _tails(tails), _headWTOCycleDepth(headWTOCycleDepth), _head(head), _nodeToWTOCycleDepth(
655
- nodeToWTOCycleDepth)
657
+ nodeToWTOCycleDepth), _graph(graph)
656
658
  {
657
659
  }
658
660
 
@@ -666,15 +668,27 @@ protected:
666
668
 
667
669
  virtual void visit(const CFBasicBlockGWTONode &node) override
668
670
  {
669
- for (const auto &edge: node.node()->getOutEdges())
671
+ if(const CallICFGNode* callNode = SVFUtil::dyn_cast<CallICFGNode>(node.node()->getICFGNodes().front()))
670
672
  {
671
- const CFBasicBlockNode *succ = edge->getDstNode();
673
+ const CFBasicBlockNode *succ = _graph->getCFBasicBlockNode(callNode->getRetICFGNode()->getId());
672
674
  const CFBasicBlockGWTOCycleDepth &succNesting = getWTOCycleDepth(succ);
673
675
  if (succ != _head && succNesting <= _headWTOCycleDepth)
674
676
  {
675
677
  _tails.insert(node.node());
676
678
  }
677
679
  }
680
+ else
681
+ {
682
+ for (const auto &edge: node.node()->getOutEdges())
683
+ {
684
+ const CFBasicBlockNode *succ = edge->getDstNode();
685
+ const CFBasicBlockGWTOCycleDepth &succNesting = getWTOCycleDepth(succ);
686
+ if (succ != _head && succNesting <= _headWTOCycleDepth)
687
+ {
688
+ _tails.insert(node.node());
689
+ }
690
+ }
691
+ }
678
692
  }
679
693
 
680
694
  protected:
@@ -746,14 +760,25 @@ protected:
746
760
  const CFBasicBlockGWTOCycle *component(const CFBasicBlockNode *node)
747
761
  {
748
762
  WTOCompRefList partition;
749
- for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
763
+ if (const CallICFGNode* callNode = SVFUtil::dyn_cast<CallICFGNode>(node->getICFGNodes().front()))
750
764
  {
751
- const CFBasicBlockNode *succ = (*it)->getDstNode();
765
+ const CFBasicBlockNode *succ = _graph->getCFBasicBlockNode(callNode->getRetICFGNode()->getId());
752
766
  if (getCDN(succ) == 0)
753
767
  {
754
768
  visit(succ, partition);
755
769
  }
756
770
  }
771
+ else
772
+ {
773
+ for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
774
+ {
775
+ const CFBasicBlockNode *succ = (*it)->getDstNode();
776
+ if (getCDN(succ) == 0)
777
+ {
778
+ visit(succ, partition);
779
+ }
780
+ }
781
+ }
757
782
  const CFBasicBlockGWTOCycle *ptr = newCycle(node, partition);
758
783
  _headToCycle.emplace(node, ptr);
759
784
  return ptr;
@@ -771,9 +796,9 @@ protected:
771
796
  head = _num;
772
797
  setCDN(node, head);
773
798
  loop = false;
774
- for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
799
+ if (const CallICFGNode* callNode = SVFUtil::dyn_cast<CallICFGNode>(node->getICFGNodes().front()))
775
800
  {
776
- const CFBasicBlockNode *succ = (*it)->getDstNode();
801
+ const CFBasicBlockNode *succ = _graph->getCFBasicBlockNode(callNode->getRetICFGNode()->getId());
777
802
  CycleDepthNumber succ_dfn = getCDN(succ);
778
803
  if (succ_dfn == CycleDepthNumber(0))
779
804
  {
@@ -789,6 +814,27 @@ protected:
789
814
  loop = true;
790
815
  }
791
816
  }
817
+ else
818
+ {
819
+ for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
820
+ {
821
+ const CFBasicBlockNode *succ = (*it)->getDstNode();
822
+ CycleDepthNumber succ_dfn = getCDN(succ);
823
+ if (succ_dfn == CycleDepthNumber(0))
824
+ {
825
+ min = visit(succ, partition);
826
+ }
827
+ else
828
+ {
829
+ min = succ_dfn;
830
+ }
831
+ if (min <= head)
832
+ {
833
+ head = min;
834
+ loop = true;
835
+ }
836
+ }
837
+ }
792
838
  if (head == getCDN(node))
793
839
  {
794
840
  setCDN(node, UINT_MAX);
@@ -826,7 +872,7 @@ protected:
826
872
  for (const auto &head: _headToCycle)
827
873
  {
828
874
  NodeRefSet tails;
829
- TailBuilder builder(_nodeToDepth, tails, head.first, getWTOCycleDepth(head.first));
875
+ TailBuilder builder(_graph, _nodeToDepth, tails, head.first, getWTOCycleDepth(head.first));
830
876
  for (auto it = head.second->begin(), eit = head.second->end(); it != eit; ++it)
831
877
  {
832
878
  (*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
  bool hasCFBasicBlockEdge(CFBasicBlockNode *src, CFBasicBlockNode *dst, ICFGEdge *icfgEdge)
404
379
  {
405
380
  CFBasicBlockEdge edge(src, dst, icfgEdge);
@@ -488,24 +463,6 @@ public:
488
463
  }
489
464
  };
490
465
 
491
- class CFBasicBlockGBuilder
492
- {
493
-
494
- private:
495
- CFBasicBlockGraph* _CFBasicBlockG;
496
-
497
- public:
498
- CFBasicBlockGBuilder() : _CFBasicBlockG() {}
499
-
500
- virtual void build(SVFModule* module);
501
-
502
- virtual void build(ICFG* icfg);
503
-
504
- inline CFBasicBlockGraph* getCFBasicBlockGraph()
505
- {
506
- return _CFBasicBlockG;
507
- }
508
- };
509
466
  }
510
467
 
511
468
  namespace SVF
@@ -534,6 +491,10 @@ struct GenericGraphTraits<SVF::CFBasicBlockGraph *>
534
491
  typedef SVF::CFBasicBlockNode *NodeRef;
535
492
  };
536
493
 
494
+ } // End namespace SVF
495
+
496
+ namespace SVF
497
+ {
537
498
  template<>
538
499
  struct DOTGraphTraits<SVF::CFBasicBlockGraph *> : public DOTGraphTraits<SVF::SVFIR *>
539
500
  {
@@ -571,22 +532,73 @@ struct DOTGraphTraits<SVF::CFBasicBlockGraph *> : public DOTGraphTraits<SVF::SVF
571
532
  {
572
533
  std::string str;
573
534
  std::stringstream rawstr(str);
574
- rawstr << "color=black";
535
+ if(node->getICFGNodes().size() == 1)
536
+ {
537
+ const ICFGNode* n = node->getICFGNodes()[0];
538
+ if(SVFUtil::isa<IntraICFGNode>(n))
539
+ {
540
+ rawstr << "color=black";
541
+ }
542
+ else if(SVFUtil::isa<FunEntryICFGNode>(n))
543
+ {
544
+ rawstr << "color=yellow";
545
+ }
546
+ else if(SVFUtil::isa<FunExitICFGNode>(n))
547
+ {
548
+ rawstr << "color=green";
549
+ }
550
+ else if(SVFUtil::isa<CallICFGNode>(n))
551
+ {
552
+ rawstr << "color=red";
553
+ }
554
+ else if(SVFUtil::isa<RetICFGNode>(n))
555
+ {
556
+ rawstr << "color=blue";
557
+ }
558
+ else if(SVFUtil::isa<GlobalICFGNode>(n))
559
+ {
560
+ rawstr << "color=purple";
561
+ }
562
+ else
563
+ assert(false && "no such kind of node!!");
564
+ }
565
+ else
566
+ {
567
+ rawstr << "color=black";
568
+ }
569
+ rawstr << "";
575
570
  return rawstr.str();
576
571
  }
577
572
 
578
573
  template<class EdgeIter>
579
574
  static std::string getEdgeAttributes(NodeType *, EdgeIter EI, SVF::CFBasicBlockGraph *)
580
575
  {
581
- return "style=solid";
576
+ CFBasicBlockEdge* edge = *(EI.getCurrent());
577
+ 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";
582
+ else
583
+ return "style=solid";
584
+ return "";
582
585
  }
583
586
 
584
587
  template<class EdgeIter>
585
588
  static std::string getEdgeSourceLabel(NodeType *, EdgeIter EI)
586
589
  {
587
- return "";
590
+ CFBasicBlockEdge* edge = *(EI.getCurrent());
591
+ assert(edge && "No edge found!!");
592
+
593
+ std::string str;
594
+ 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
+
600
+ return rawstr.str();
588
601
  }
589
602
  };
590
-
591
- } // End namespace SVF
603
+ }
592
604
  #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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-lib",
3
- "version": "1.0.1680",
3
+ "version": "1.0.1682",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {