svf-lib 1.0.2183 → 1.0.2184

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.
@@ -331,12 +331,11 @@ class ObjVar: public SVFVar
331
331
  friend class SVFIRReader;
332
332
 
333
333
  protected:
334
- const MemObj* mem; ///< memory object
335
334
  /// Constructor to create an empty ObjVar (for SVFIRReader/deserialization)
336
- ObjVar(NodeID i, PNODEK ty = ObjNode) : SVFVar(i, ty), mem{} {}
335
+ ObjVar(NodeID i, PNODEK ty = ObjNode) : SVFVar(i, ty) {}
337
336
  /// Constructor
338
- ObjVar(const SVFValue* val, NodeID i, const MemObj* m, PNODEK ty = ObjNode) :
339
- SVFVar(val, i, ty), mem(m)
337
+ ObjVar(const SVFValue* val, NodeID i, PNODEK ty = ObjNode) :
338
+ SVFVar(val, i, ty)
340
339
  {
341
340
  }
342
341
  public:
@@ -360,12 +359,6 @@ public:
360
359
  }
361
360
  //@}
362
361
 
363
- /// Return memory object
364
- const MemObj* getMemObj() const
365
- {
366
- return mem;
367
- }
368
-
369
362
  /// Return name of a LLVM value
370
363
  virtual const std::string getValueName() const
371
364
  {
@@ -376,7 +369,7 @@ public:
376
369
  /// Return type of the value
377
370
  inline virtual const SVFType* getType() const
378
371
  {
379
- return mem->getType();
372
+ return value->getType();
380
373
  }
381
374
 
382
375
  virtual const std::string toString() const;
@@ -535,149 +528,299 @@ public:
535
528
  virtual const std::string toString() const;
536
529
  };
537
530
 
538
-
539
531
  /*
540
- * Gep Obj variable, this is dynamic generated for field sensitive analysis
541
- * Each gep obj variable is one field of a MemObj (base)
532
+ * Field-insensitive Gep Obj variable, this is dynamic generated for field sensitive analysis
533
+ * Each field-insensitive gep obj node represents all fields of a MemObj (base)
542
534
  */
543
- class GepObjVar: public ObjVar
535
+ class BaseObjVar : public ObjVar
544
536
  {
545
537
  friend class SVFIRWriter;
546
538
  friend class SVFIRReader;
547
-
539
+ friend class SVFIRBuilder;
548
540
  private:
549
- APOffset apOffset = 0;
550
- NodeID base = 0;
541
+ ObjTypeInfo* typeInfo;
551
542
 
552
- /// Constructor to create empty GepObjVar (for SVFIRReader/deserialization)
553
- // only for reading from file when we don't have MemObj*
554
- GepObjVar(NodeID i, PNODEK ty = GepObjNode) : ObjVar(i, ty) {}
543
+ const SVFBaseNode* gNode;
544
+
545
+ protected:
546
+ /// Constructor to create empty ObjVar (for SVFIRReader/deserialization)
547
+ BaseObjVar(NodeID i, PNODEK ty = BaseObjNode) : ObjVar(i, ty) {}
555
548
 
556
549
  public:
557
- /// Methods for support type inquiry through isa, cast, and dyn_cast:
550
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
558
551
  //@{
559
- static inline bool classof(const GepObjVar*)
552
+ static inline bool classof(const BaseObjVar*)
560
553
  {
561
554
  return true;
562
555
  }
563
556
  static inline bool classof(const ObjVar* node)
564
557
  {
565
- return node->getNodeKind() == SVFVar::GepObjNode;
558
+ return isBaseObjVarKinds(node->getNodeKind());
566
559
  }
567
560
  static inline bool classof(const SVFVar* node)
568
561
  {
569
- return node->getNodeKind() == SVFVar::GepObjNode;
562
+ return isBaseObjVarKinds(node->getNodeKind());
570
563
  }
571
564
  static inline bool classof(const GenericPAGNodeTy* node)
572
565
  {
573
- return node->getNodeKind() == SVFVar::GepObjNode;
566
+ return isBaseObjVarKinds(node->getNodeKind());
574
567
  }
575
568
  static inline bool classof(const SVFBaseNode* node)
576
569
  {
577
- return node->getNodeKind() == SVFVar::GepObjNode;
570
+ return isBaseObjVarKinds(node->getNodeKind());
578
571
  }
579
572
  //@}
580
573
 
581
- /// Constructor
582
- GepObjVar(const MemObj* mem, NodeID i, const APOffset& apOffset,
583
- PNODEK ty = GepObjNode)
584
- : ObjVar(mem->getValue(), i, mem, ty), apOffset(apOffset)
574
+ /// Constructorx
575
+ BaseObjVar(const SVFValue* val, NodeID i, ObjTypeInfo* ti, PNODEK ty = BaseObjNode)
576
+ : ObjVar(val, i, ty), typeInfo(ti)
585
577
  {
586
- base = mem->getId();
587
578
  }
588
579
 
589
- /// offset of the mem object
590
- inline APOffset getConstantFieldIdx() const
580
+ virtual const BaseObjVar* getBaseMemObj() const
591
581
  {
592
- return apOffset;
582
+ return this;
593
583
  }
594
584
 
595
- /// Set the base object from which this GEP node came from.
596
- inline void setBaseNode(NodeID bs)
585
+ /// Get the reference value to this object
586
+ inline const SVFBaseNode* getGNode() const
597
587
  {
598
- this->base = bs;
588
+ return gNode;
599
589
  }
600
590
 
601
- /// Return the base object from which this GEP node came from.
602
- inline NodeID getBaseNode(void) const
591
+ /// Return name of a LLVM value
592
+ inline const std::string getValueName() const
603
593
  {
604
- return base;
594
+ if (value)
595
+ return value->getName() + " (base object)";
596
+ return " (base object)";
605
597
  }
606
598
 
607
- /// Return the type of this gep object
608
- inline virtual const SVFType* getType() const
599
+ virtual const std::string toString() const;
600
+
601
+ /// Get the memory object id
602
+ inline SymID getId() const
609
603
  {
610
- return SymbolTableInfo::SymbolInfo()->getFlatternedElemType(mem->getType(), apOffset);
604
+ return id;
611
605
  }
612
606
 
613
- /// Return name of a LLVM value
614
- inline const std::string getValueName() const
607
+ /// Get obj type
608
+ const SVFType* getType() const
615
609
  {
616
- if (value)
617
- return value->getName() + "_" + std::to_string(apOffset);
618
- return "offset_" + std::to_string(apOffset);
610
+ return typeInfo->getType();
619
611
  }
620
612
 
621
- virtual const std::string toString() const;
613
+ /// Get the number of elements of this object
614
+ u32_t getNumOfElements() const
615
+ {
616
+ return typeInfo->getNumOfElements();
617
+ }
618
+
619
+ /// Set the number of elements of this object
620
+ void setNumOfElements(u32_t num)
621
+ {
622
+ return typeInfo->setNumOfElements(num);
623
+ }
624
+
625
+ /// Get max field offset limit
626
+ u32_t getMaxFieldOffsetLimit() const
627
+ {
628
+ return typeInfo->getMaxFieldOffsetLimit();
629
+ }
630
+
631
+
632
+ /// Return true if its field limit is 0
633
+ bool isFieldInsensitive() const
634
+ {
635
+ return getMaxFieldOffsetLimit() == 0;
636
+ }
637
+
638
+ /// Set the memory object to be field insensitive
639
+ void setFieldInsensitive()
640
+ {
641
+ typeInfo->setMaxFieldOffsetLimit(0);
642
+ }
643
+
644
+
645
+ /// Set the memory object to be field sensitive (up to max field limit)
646
+ void setFieldSensitive()
647
+ {
648
+ typeInfo->setMaxFieldOffsetLimit(typeInfo->getNumOfElements());
649
+ }
650
+
651
+ /// Whether it is a black hole object
652
+ bool isBlackHoleObj() const
653
+ {
654
+ return SymbolTableInfo::isBlkObj(getId());
655
+ }
656
+
657
+ /// Get the byte size of this object
658
+ u32_t getByteSizeOfObj() const
659
+ {
660
+ return typeInfo->getByteSizeOfObj();
661
+ }
662
+
663
+ /// Check if byte size is a const value
664
+ bool isConstantByteSize() const
665
+ {
666
+ return typeInfo->isConstantByteSize();
667
+ }
668
+
669
+
670
+ /// object attributes methods
671
+ //@{
672
+ bool isFunction() const
673
+ {
674
+ return typeInfo->isFunction();
675
+ }
676
+ bool isGlobalObj() const
677
+ {
678
+ return typeInfo->isGlobalObj();
679
+ }
680
+ bool isStaticObj() const
681
+ {
682
+ return typeInfo->isStaticObj();
683
+ }
684
+ bool isStack() const
685
+ {
686
+ return typeInfo->isStack();
687
+ }
688
+ bool isHeap() const
689
+ {
690
+ return typeInfo->isHeap();
691
+ }
692
+ bool isStruct() const
693
+ {
694
+ return typeInfo->isStruct();
695
+ }
696
+ bool isArray() const
697
+ {
698
+ return typeInfo->isArray();
699
+ }
700
+ bool isVarStruct() const
701
+ {
702
+ return typeInfo->isVarStruct();
703
+ }
704
+ bool isVarArray() const
705
+ {
706
+ return typeInfo->isVarArray();
707
+ }
708
+ bool isConstantStruct() const
709
+ {
710
+ return typeInfo->isConstantStruct();
711
+ }
712
+ bool isConstantArray() const
713
+ {
714
+ return typeInfo->isConstantArray();
715
+ }
716
+ bool isConstDataOrConstGlobal() const
717
+ {
718
+ return typeInfo->isConstDataOrConstGlobal();
719
+ }
720
+ bool isConstDataOrAggData() const
721
+ {
722
+ return typeInfo->isConstDataOrAggData();
723
+ }
724
+ //@}
725
+
726
+ /// Clean up memory
727
+ void destroy()
728
+ {
729
+ delete typeInfo;
730
+ typeInfo = nullptr;
731
+ }
732
+
733
+
622
734
  };
623
735
 
736
+
624
737
  /*
625
- * Field-insensitive Gep Obj variable, this is dynamic generated for field sensitive analysis
626
- * Each field-insensitive gep obj node represents all fields of a MemObj (base)
738
+ * Gep Obj variable, this is dynamic generated for field sensitive analysis
739
+ * Each gep obj variable is one field of a BaseObjVar (base)
627
740
  */
628
- class BaseObjVar : public ObjVar
741
+ class GepObjVar: public ObjVar
629
742
  {
630
743
  friend class SVFIRWriter;
631
744
  friend class SVFIRReader;
632
745
 
633
- protected:
634
- /// Constructor to create empty ObjVar (for SVFIRReader/deserialization)
635
- BaseObjVar(NodeID i, PNODEK ty = BaseObjNode) : ObjVar(i, ty) {}
746
+ private:
747
+ APOffset apOffset = 0;
748
+
749
+ const BaseObjVar* base;
750
+
751
+ /// Constructor to create empty GepObjVar (for SVFIRReader/deserialization)
752
+ // only for reading from file when we don't have BaseObjVar*
753
+ GepObjVar(NodeID i, PNODEK ty = GepObjNode) : ObjVar(i, ty), base{} {}
636
754
 
637
755
  public:
638
- /// Methods for support type inquiry through isa, cast, and dyn_cast:
756
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
639
757
  //@{
640
- static inline bool classof(const BaseObjVar*)
758
+ static inline bool classof(const GepObjVar*)
641
759
  {
642
760
  return true;
643
761
  }
644
762
  static inline bool classof(const ObjVar* node)
645
763
  {
646
- return isBaseObjVarKinds(node->getNodeKind());
764
+ return node->getNodeKind() == SVFVar::GepObjNode;
647
765
  }
648
766
  static inline bool classof(const SVFVar* node)
649
767
  {
650
- return isBaseObjVarKinds(node->getNodeKind());
768
+ return node->getNodeKind() == SVFVar::GepObjNode;
651
769
  }
652
770
  static inline bool classof(const GenericPAGNodeTy* node)
653
771
  {
654
- return isBaseObjVarKinds(node->getNodeKind());
772
+ return node->getNodeKind() == SVFVar::GepObjNode;
655
773
  }
656
774
  static inline bool classof(const SVFBaseNode* node)
657
775
  {
658
- return isBaseObjVarKinds(node->getNodeKind());
776
+ return node->getNodeKind() == SVFVar::GepObjNode;
659
777
  }
660
778
  //@}
661
779
 
662
780
  /// Constructor
663
- BaseObjVar(const SVFValue* val, NodeID i, const MemObj* mem,
664
- PNODEK ty = BaseObjNode)
665
- : ObjVar(val, i, mem, ty)
781
+ GepObjVar(const BaseObjVar* baseObj, NodeID i,
782
+ const APOffset& apOffset, PNODEK ty = GepObjNode)
783
+ : ObjVar(baseObj->hasValue()? baseObj->getValue(): nullptr, i, ty), apOffset(apOffset), base(baseObj)
784
+ {
785
+
786
+ }
787
+
788
+ /// offset of the mem object
789
+ inline APOffset getConstantFieldIdx() const
790
+ {
791
+ return apOffset;
792
+ }
793
+
794
+ /// Return the base object from which this GEP node came from.
795
+ inline NodeID getBaseNode(void) const
796
+ {
797
+ return base->getId();
798
+ }
799
+
800
+ inline const BaseObjVar* getBaseObj() const
666
801
  {
802
+ return base;
803
+ }
804
+
805
+ /// Return the type of this gep object
806
+ inline virtual const SVFType* getType() const
807
+ {
808
+ return SymbolTableInfo::SymbolInfo()->getFlatternedElemType(value->getType(), apOffset);
667
809
  }
668
810
 
669
811
  /// Return name of a LLVM value
670
812
  inline const std::string getValueName() const
671
813
  {
672
814
  if (value)
673
- return value->getName() + " (base object)";
674
- return " (base object)";
815
+ return value->getName() + "_" + std::to_string(apOffset);
816
+ return "offset_" + std::to_string(apOffset);
675
817
  }
676
818
 
677
819
  virtual const std::string toString() const;
678
820
  };
679
821
 
680
822
 
823
+
681
824
  /**
682
825
  * @brief Class representing a heap object variable in the SVFIR
683
826
  *
@@ -724,8 +867,13 @@ public:
724
867
  //@}
725
868
 
726
869
  /// Constructor
727
- HeapObjVar(NodeID i, const MemObj* mem, const SVFType* svfType,
728
- const SVFFunction* fun, PNODEK ty = HeapObjNode);
870
+ HeapObjVar(const SVFValue* val, NodeID i, ObjTypeInfo* ti,
871
+ const SVFFunction* f, PNODEK ty = HeapObjNode):
872
+ BaseObjVar(val, i, ti, ty)
873
+ {
874
+ isPtr = val->getType()->isPointerTy();
875
+ func = f;
876
+ }
729
877
 
730
878
  /// Return name of a LLVM value
731
879
  inline const std::string getValueName() const
@@ -785,8 +933,13 @@ public:
785
933
  //@}
786
934
 
787
935
  /// Constructor
788
- StackObjVar(NodeID i, const MemObj* mem, const SVFType* svfType,
789
- const SVFFunction* fun, PNODEK ty = StackObjNode);
936
+ StackObjVar(const SVFValue* val, NodeID i, ObjTypeInfo* ti,
937
+ const SVFFunction* fun, PNODEK ty = StackObjNode):
938
+ BaseObjVar(val, i, ti, ty)
939
+ {
940
+ isPtr = val->getType()->isPointerTy();
941
+ func = fun;
942
+ }
790
943
 
791
944
  /// Return name of a LLVM value
792
945
  inline const std::string getValueName() const
@@ -886,7 +1039,7 @@ public:
886
1039
  //@}
887
1040
 
888
1041
  /// Constructor
889
- FunObjVar(NodeID i, const MemObj* mem, const CallGraphNode* cgNode,
1042
+ FunObjVar(const SVFValue* val, NodeID i, ObjTypeInfo* ti, const CallGraphNode* cgNode,
890
1043
  PNODEK ty = FunObjNode);
891
1044
 
892
1045
  inline const CallGraphNode* getCallGraphNode() const
@@ -894,6 +1047,8 @@ public:
894
1047
  return callGraphNode;
895
1048
  }
896
1049
 
1050
+ virtual const SVFFunction* getFunction() const;
1051
+
897
1052
  virtual bool isIsolatedNode() const;
898
1053
 
899
1054
  virtual const std::string toString() const;
@@ -1221,8 +1376,8 @@ public:
1221
1376
  //@}
1222
1377
 
1223
1378
  /// Constructor
1224
- GlobalObjVar(const SVFValue* val, NodeID i, const MemObj* mem,
1225
- PNODEK ty = GlobalObjNode): BaseObjVar(val, i,mem,ty)
1379
+ GlobalObjVar(const SVFValue* val, NodeID i, ObjTypeInfo* ti,
1380
+ PNODEK ty = GlobalObjNode): BaseObjVar(val, i, ti, ty)
1226
1381
  {
1227
1382
 
1228
1383
  }
@@ -1270,8 +1425,8 @@ public:
1270
1425
  //@}
1271
1426
 
1272
1427
  /// Constructor
1273
- ConstantDataObjVar(const SVFValue* val, NodeID i, const MemObj* m, PNODEK ty = ConstantDataObjNode)
1274
- : BaseObjVar(val, i, m, ty)
1428
+ ConstantDataObjVar(const SVFValue* val, NodeID i, ObjTypeInfo* ti, PNODEK ty = ConstantDataObjNode)
1429
+ : BaseObjVar(val, i, ti, ty)
1275
1430
  {
1276
1431
  }
1277
1432
 
@@ -1327,8 +1482,8 @@ public:
1327
1482
  //@}
1328
1483
 
1329
1484
  /// Constructor
1330
- ConstantFPObjVar(const SVFValue* val, NodeID i, double dv, const MemObj* m, PNODEK ty = ConstantFPObjNode)
1331
- : ConstantDataObjVar(val, i, m, ty), dval(dv)
1485
+ ConstantFPObjVar(const SVFValue* val, NodeID i, double dv, ObjTypeInfo* ti, PNODEK ty = ConstantFPObjNode)
1486
+ : ConstantDataObjVar(val, i, ti, ty), dval(dv)
1332
1487
  {
1333
1488
  }
1334
1489
 
@@ -1402,8 +1557,8 @@ public:
1402
1557
  //@}
1403
1558
 
1404
1559
  /// Constructor
1405
- ConstantIntObjVar(const SVFValue* val, NodeID i, s64_t sv, u64_t zv, const MemObj* m, PNODEK ty = ConstantIntObjNode)
1406
- : ConstantDataObjVar(val, i, m, ty), zval(zv), sval(sv)
1560
+ ConstantIntObjVar(const SVFValue* val, NodeID i, s64_t sv, u64_t zv, ObjTypeInfo* ti, PNODEK ty = ConstantIntObjNode)
1561
+ : ConstantDataObjVar(val, i, ti, ty), zval(zv), sval(sv)
1407
1562
  {
1408
1563
  }
1409
1564
 
@@ -1457,8 +1612,8 @@ public:
1457
1612
  //@}
1458
1613
 
1459
1614
  /// Constructor
1460
- ConstantNullPtrObjVar(const SVFValue* val, NodeID i, const MemObj* m, PNODEK ty = ConstantNullptrObjNode)
1461
- : ConstantDataObjVar(val, i, m, ty)
1615
+ ConstantNullPtrObjVar(const SVFValue* val, NodeID i, ObjTypeInfo* ti, PNODEK ty = ConstantNullptrObjNode)
1616
+ : ConstantDataObjVar(val, i, ti, ty)
1462
1617
  {
1463
1618
  }
1464
1619
 
@@ -1655,8 +1810,8 @@ public:
1655
1810
  //@}
1656
1811
 
1657
1812
  /// Constructor
1658
- DummyObjVar(NodeID i, const MemObj* m, PNODEK ty = DummyObjNode)
1659
- : BaseObjVar(nullptr, i, m, ty)
1813
+ DummyObjVar(NodeID i, ObjTypeInfo* ti, PNODEK ty = DummyObjNode)
1814
+ : BaseObjVar(nullptr, i, ti, ty)
1660
1815
  {
1661
1816
  }
1662
1817