svf-tools 1.0.1045 → 1.0.1047

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.
package/build.sh CHANGED
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env bash
2
2
  # type './build.sh' for release build
3
3
  # type './build.sh debug' for debug build
4
- # if the LLVM_DIR variable is not set, LLVM will be downloaded.
4
+ # type './build.sh shared' for building LLVM from source with shared libs and RTTI enabled
5
+ # type './build.sh debug shared' for debug build with shared libs and RTTI enabled
6
+ # If the LLVM_DIR variable is not set, LLVM will be downloaded or built from source.
5
7
  #
6
8
  # Dependencies include: build-essential libncurses5 libncurses-dev cmake zlib1g-dev
7
9
  set -e # exit on first error
@@ -9,7 +11,7 @@ set -e # exit on first error
9
11
  jobs=8
10
12
 
11
13
  #########
12
- # VARs and Links
14
+ # Variables and Paths
13
15
  ########
14
16
  SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
15
17
  SVFHOME="${SCRIPT_DIR}"
@@ -30,6 +32,20 @@ LLVMHome="llvm-${MajorLLVMVer}.0.0.obj"
30
32
  Z3Home="z3.obj"
31
33
 
32
34
 
35
+ # Parse arguments
36
+ BUILD_TYPE='Release'
37
+ BUILD_SHARED='OFF'
38
+ for arg in "$@"; do
39
+ if [[ $arg =~ ^[Dd]ebug$ ]]; then
40
+ BUILD_TYPE='Debug'
41
+ fi
42
+ if [[ $arg =~ ^[Ss]hared$ ]]; then
43
+ BUILD_SHARED='ON'
44
+ fi
45
+ done
46
+
47
+
48
+
33
49
  # Downloads $1 (URL) to $2 (target destination) using wget or curl,
34
50
  # depending on OS.
35
51
  # E.g. generic_download_file www.url.com/my.zip loc/my.zip
@@ -114,8 +130,12 @@ function build_llvm_from_source {
114
130
  echo "Building LLVM..."
115
131
  mkdir llvm-build
116
132
  cd llvm-build
117
- # /*/ is a dirty hack to get llvm-project-llvmorg-version...
118
- cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$SVFHOME/$LLVMHome" -DLLVM_ENABLE_PROJECTS=clang ../llvm-source/*/llvm
133
+ cmake -DCMAKE_BUILD_TYPE=Release \
134
+ -DCMAKE_INSTALL_PREFIX="$SVFHOME/$LLVMHome" \
135
+ -DLLVM_ENABLE_PROJECTS="clang" \
136
+ -DLLVM_ENABLE_RTTI=ON \
137
+ -DBUILD_SHARED_LIBS=ON \
138
+ ../llvm-source/*/llvm
119
139
  cmake --build . -j ${jobs}
120
140
  cmake --install .
121
141
 
@@ -186,13 +206,18 @@ if [[ ! -d "$LLVM_DIR" ]]; then
186
206
  mkdir -p $SVFHOME/$LLVMHome
187
207
  ln -s $(brew --prefix llvm@${MajorLLVMVer})/* $SVFHOME/$LLVMHome
188
208
  else
209
+ # Ubuntu if build_shared in ON,
210
+ if [[ "$BUILD_SHARED" == "ON" ]]; then
211
+ build_llvm_from_source
212
+ else
189
213
  # everything else downloads pre-built lib includ osx "arm64"
190
- echo "Downloading LLVM binary for $OSDisplayName"
191
- generic_download_file "$urlLLVM" llvm.tar.xz
192
- check_xz
193
- echo "Unzipping llvm package..."
194
- mkdir -p "./$LLVMHome" && tar -xf llvm.tar.xz -C "./$LLVMHome" --strip-components 1
195
- rm llvm.tar.xz
214
+ echo "Downloading LLVM binary for $OSDisplayName"
215
+ generic_download_file "$urlLLVM" llvm.tar.xz
216
+ check_xz
217
+ echo "Unzipping llvm package..."
218
+ mkdir -p "./$LLVMHome" && tar -xf llvm.tar.xz -C "./$LLVMHome" --strip-components 1
219
+ rm llvm.tar.xz
220
+ fi
196
221
  fi
197
222
  fi
198
223
  export LLVM_DIR="$SVFHOME/$LLVMHome"
@@ -253,7 +278,7 @@ mkdir "${BUILD_DIR}"
253
278
  cmake -D CMAKE_BUILD_TYPE:STRING="${BUILD_TYPE}" \
254
279
  -DSVF_ENABLE_ASSERTIONS:BOOL=true \
255
280
  -DSVF_SANITIZE="${SVF_SANITIZER}" \
256
- -DBUILD_SHARED_LIBS=off \
281
+ -DBUILD_SHARED_LIBS=${BUILD_SHARED} \
257
282
  -S "${SVFHOME}" -B "${BUILD_DIR}"
258
283
  cmake --build "${BUILD_DIR}" -j ${jobs}
259
284
 
@@ -265,4 +290,4 @@ source ${SVFHOME}/setup.sh ${BUILD_TYPE}
265
290
  #########
266
291
  # Optionally, you can also specify a CXX_COMPILER and your $LLVM_HOME for your build
267
292
  # cmake -DCMAKE_CXX_COMPILER=$LLVM_DIR/bin/clang++ -DLLVM_DIR=$LLVM_DIR
268
- #########
293
+ #########
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-tools",
3
- "version": "1.0.1045",
3
+ "version": "1.0.1047",
4
4
  "description": "* <b>[TypeClone](https://github.com/SVF-tools/SVF/wiki/TypeClone) published in our [ECOOP paper](https://yuleisui.github.io/publications/ecoop20.pdf) is now available in SVF </b> * <b>SVF now uses a single script for its build. Just type [`source ./build.sh`](https://github.com/SVF-tools/SVF/blob/master/build.sh) in your terminal, that's it!</b> * <b>SVF now supports LLVM-10.0.0! </b> * <b>We thank [bsauce](https://github.com/bsauce) for writing a user manual of SVF ([link1](https://www.jianshu.com/p/068a08ec749c) and [link2](https://www.jianshu.com/p/777c30d4240e)) in Chinese </b> * <b>SVF now supports LLVM-9.0.0 (Thank [Byoungyoung Lee](https://github.com/SVF-tools/SVF/issues/142) for his help!). </b> * <b>SVF now supports a set of [field-sensitive pointer analyses](https://yuleisui.github.io/publications/sas2019a.pdf). </b> * <b>[Use SVF as an external lib](https://github.com/SVF-tools/SVF/wiki/Using-SVF-as-a-lib-in-your-own-tool) for your own project (Contributed by [Hongxu Chen](https://github.com/HongxuChen)). </b> * <b>SVF now supports LLVM-7.0.0. </b> * <b>SVF now supports Docker. [Try SVF in Docker](https://github.com/SVF-tools/SVF/wiki/Try-SVF-in-Docker)! </b> * <b>SVF now supports [LLVM-6.0.0](https://github.com/svf-tools/SVF/pull/38) (Contributed by [Jack Anthony](https://github.com/jackanth)). </b> * <b>SVF now supports [LLVM-4.0.0](https://github.com/svf-tools/SVF/pull/23) (Contributed by Jared Carlson. Thank [Jared](https://github.com/jcarlson23) and [Will](https://github.com/dtzWill) for their in-depth [discussions](https://github.com/svf-tools/SVF/pull/18) about updating SVF!) </b> * <b>SVF now supports analysis for C++ programs.</b> <br />",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,4 +1,5 @@
1
1
  #include "Graphs/BasicBlockG.h"
2
+ #include "Graphs/ICFGNode.h"
2
3
 
3
4
  using namespace SVF;
4
5
  const std::string BasicBlockEdge::toString() const
@@ -8,3 +9,16 @@ const std::string BasicBlockEdge::toString() const
8
9
  rawstr << "BasicBlockEdge: " << getSrcNode()->toString() << " -> " << getDstNode()->getName();
9
10
  return rawstr.str();
10
11
  }
12
+
13
+ const std::string SVFBasicBlock::toString() const
14
+ {
15
+ std::string str;
16
+ std::stringstream rawstr(str);
17
+ rawstr << "----------"<< "SVFBasicBlock: " << getName() <<"----------\n";
18
+ for (const ICFGNode* icfgNode : allICFGNodes)
19
+ {
20
+ rawstr << icfgNode->toString();
21
+ }
22
+ rawstr << "\n----------------------------------------\n";
23
+ return rawstr.str();
24
+ }
@@ -71,10 +71,6 @@ public:
71
71
  SVFArg,
72
72
  SVFConst,
73
73
  SVFConstData,
74
- SVFConstInt,
75
- SVFConstFP,
76
- SVFNullPtr,
77
- SVFBlackHole,
78
74
  SVFMetaAsValue,
79
75
  SVFOther
80
76
  };
@@ -138,14 +134,6 @@ public:
138
134
  {
139
135
  return ptrInUncalledFun;
140
136
  }
141
- inline bool isblackHole() const
142
- {
143
- return getKind() == SVFBlackHole;;
144
- }
145
- inline bool isNullPtr() const
146
- {
147
- return getKind() == SVFNullPtr;
148
- }
149
137
  inline virtual void setSourceLoc(const std::string& sourceCodeInfo)
150
138
  {
151
139
  sourceLoc = sourceCodeInfo;
@@ -526,11 +514,7 @@ public:
526
514
  {
527
515
  return node->getKind() == SVFConst ||
528
516
  node->getKind() == SVFGlob ||
529
- node->getKind() == SVFConstData ||
530
- node->getKind() == SVFConstInt ||
531
- node->getKind() == SVFConstFP ||
532
- node->getKind() == SVFNullPtr ||
533
- node->getKind() == SVFBlackHole;
517
+ node->getKind() == SVFConstData;
534
518
  }
535
519
 
536
520
  };
@@ -629,124 +613,11 @@ public:
629
613
 
630
614
  static inline bool classof(const SVFLLVMValue *node)
631
615
  {
632
- return node->getKind() == SVFConstData ||
633
- node->getKind() == SVFConstInt ||
634
- node->getKind() == SVFConstFP ||
635
- node->getKind() == SVFNullPtr ||
636
- node->getKind() == SVFBlackHole;
637
- }
638
- static inline bool classof(const SVFConstantData *node)
639
- {
640
- return node->getKind() == SVFConstData ||
641
- node->getKind() == SVFConstInt ||
642
- node->getKind() == SVFConstFP ||
643
- node->getKind() == SVFNullPtr ||
644
- node->getKind() == SVFBlackHole;
645
- }
646
- };
647
-
648
- class SVFConstantInt : public SVFConstantData
649
- {
650
- friend class SVFIRWriter;
651
- friend class SVFIRReader;
652
- private:
653
- u64_t zval;
654
- s64_t sval;
655
- public:
656
- SVFConstantInt(const SVFType* ty, u64_t z, s64_t s)
657
- : SVFConstantData(ty, SVFLLVMValue::SVFConstInt), zval(z), sval(s)
658
- {
659
- }
660
- SVFConstantInt() = delete;
661
-
662
- static inline bool classof(const SVFLLVMValue *node)
663
- {
664
- return node->getKind() == SVFConstInt;
665
- }
666
- static inline bool classof(const SVFConstantData *node)
667
- {
668
- return node->getKind() == SVFConstInt;
669
- }
670
- // Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate for the type of this constant.
671
- inline u64_t getZExtValue () const
672
- {
673
- return zval;
674
- }
675
- // Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the type of this constant
676
- inline s64_t getSExtValue () const
677
- {
678
- return sval;
679
- }
680
- };
681
-
682
- class SVFConstantFP : public SVFConstantData
683
- {
684
- friend class SVFIRWriter;
685
- friend class SVFIRReader;
686
- private:
687
- float dval;
688
- public:
689
- SVFConstantFP(const SVFType* ty, double d)
690
- : SVFConstantData(ty, SVFLLVMValue::SVFConstFP), dval(d)
691
- {
692
- }
693
- SVFConstantFP() = delete;
694
-
695
- inline double getFPValue () const
696
- {
697
- return dval;
698
- }
699
- static inline bool classof(const SVFLLVMValue *node)
700
- {
701
- return node->getKind() == SVFConstFP;
702
- }
703
- static inline bool classof(const SVFConstantData *node)
704
- {
705
- return node->getKind() == SVFConstFP;
706
- }
707
- };
708
-
709
- class SVFConstantNullPtr : public SVFConstantData
710
- {
711
- friend class SVFIRWriter;
712
- friend class SVFIRReader;
713
-
714
- public:
715
- SVFConstantNullPtr(const SVFType* ty)
716
- : SVFConstantData(ty, SVFLLVMValue::SVFNullPtr)
717
- {
718
- }
719
- SVFConstantNullPtr() = delete;
720
-
721
- static inline bool classof(const SVFLLVMValue *node)
722
- {
723
- return node->getKind() == SVFNullPtr;
724
- }
725
- static inline bool classof(const SVFConstantData *node)
726
- {
727
- return node->getKind() == SVFNullPtr;
728
- }
729
- };
730
-
731
- class SVFBlackHoleValue : public SVFConstantData
732
- {
733
- friend class SVFIRWriter;
734
- friend class SVFIRReader;
735
-
736
- public:
737
- SVFBlackHoleValue(const SVFType* ty)
738
- : SVFConstantData(ty, SVFLLVMValue::SVFBlackHole)
739
- {
740
- }
741
- SVFBlackHoleValue() = delete;
742
-
743
- static inline bool classof(const SVFLLVMValue *node)
744
- {
745
- return node->getKind() == SVFBlackHole;
616
+ return node->getKind() == SVFConstData;
746
617
  }
747
618
  static inline bool classof(const SVFConstantData *node)
748
619
  {
749
- return node->getKind() == SVFBlackHole;
620
+ return node->getKind() == SVFConstData;
750
621
  }
751
622
  };
752
623
 
@@ -1211,9 +1211,10 @@ void LLVMModuleSet::dumpModulesToFile(const std::string& suffix)
1211
1211
 
1212
1212
  NodeID LLVMModuleSet::getValueNode(const SVFLLVMValue *val)
1213
1213
  {
1214
- if (val->isNullPtr())
1214
+ auto llvm_value = llvmModuleSet->getLLVMValue(val);
1215
+ if (SVFUtil::isa<ConstantPointerNull>(llvm_value))
1215
1216
  return svfir->nullPtrSymID();
1216
- else if (val->isblackHole())
1217
+ else if (SVFUtil::isa<UndefValue>(llvm_value))
1217
1218
  return svfir->blkPtrSymID();
1218
1219
  else
1219
1220
  {
@@ -1224,7 +1225,7 @@ NodeID LLVMModuleSet::getValueNode(const SVFLLVMValue *val)
1224
1225
  }
1225
1226
  bool LLVMModuleSet::hasValueNode(const SVFLLVMValue *val)
1226
1227
  {
1227
- if (val->isNullPtr() || val->isblackHole())
1228
+ if (SVFUtil::isa<ConstantPointerNull, UndefValue>(llvmModuleSet->getLLVMValue(val)))
1228
1229
  return true;
1229
1230
  else
1230
1231
  return (valSymMap.find(val) != valSymMap.end());
@@ -1326,55 +1327,7 @@ SVFConstantData* LLVMModuleSet::getSVFConstantData(const ConstantData* cd)
1326
1327
  }
1327
1328
  else
1328
1329
  {
1329
- SVFConstantData* svfcd = nullptr;
1330
- if(const ConstantInt* cint = SVFUtil::dyn_cast<ConstantInt>(cd))
1331
- {
1332
- /// bitwidth == 1 : cint has value from getZExtValue() because `bool true` will be translated to -1 using sign extension (i.e., getSExtValue).
1333
- /// bitwidth <=64 1 : cint has value from getSExtValue()
1334
- /// bitwidth >64 1 : cint has value 0 because it represents an invalid int
1335
- if(cint->getBitWidth() == 1)
1336
- svfcd = new SVFConstantInt(getSVFType(cint->getType()), cint->getZExtValue(), cint->getZExtValue());
1337
- else if(cint->getBitWidth() <= 64 && cint->getBitWidth() > 1)
1338
- svfcd = new SVFConstantInt(getSVFType(cint->getType()), cint->getZExtValue(), cint->getSExtValue());
1339
- else
1340
- svfcd = new SVFConstantInt(getSVFType(cint->getType()), 0, 0);
1341
- }
1342
- else if(const ConstantFP* cfp = SVFUtil::dyn_cast<ConstantFP>(cd))
1343
- {
1344
- double dval = 0;
1345
- // TODO: Why only double is considered? What about float?
1346
- if (cfp->isNormalFP())
1347
- {
1348
- const llvm::fltSemantics& semantics = cfp->getValueAPF().getSemantics();
1349
- if (&semantics == &llvm::APFloat::IEEEhalf() ||
1350
- &semantics == &llvm::APFloat::IEEEsingle() ||
1351
- &semantics == &llvm::APFloat::IEEEdouble() ||
1352
- &semantics == &llvm::APFloat::IEEEquad() ||
1353
- &semantics == &llvm::APFloat::x87DoubleExtended())
1354
- {
1355
- dval = cfp->getValueAPF().convertToDouble();
1356
- }
1357
- else
1358
- {
1359
- assert (false && "Unsupported floating point type");
1360
- abort();
1361
- }
1362
- }
1363
- else
1364
- {
1365
- // other cfp type, like isZero(), isInfinity(), isNegative(), etc.
1366
- // do nothing
1367
- }
1368
- svfcd = new SVFConstantFP(getSVFType(cd->getType()), dval);
1369
- }
1370
- else if(SVFUtil::isa<ConstantPointerNull>(cd))
1371
- svfcd = new SVFConstantNullPtr(getSVFType(cd->getType()));
1372
- else if (SVFUtil::isa<UndefValue>(cd))
1373
- svfcd = new SVFBlackHoleValue(getSVFType(cd->getType()));
1374
- else
1375
- svfcd = new SVFConstantData(getSVFType(cd->getType()));
1376
-
1377
-
1330
+ SVFConstantData* svfcd = new SVFConstantData(getSVFType(cd->getType()));
1378
1331
  svfModule->addConstant(svfcd);
1379
1332
  addConstantDataMap(cd,svfcd);
1380
1333
  return svfcd;
@@ -763,19 +763,6 @@ std::string SVFLLVMValue::toString() const
763
763
  return rawstr.str();
764
764
  }
765
765
 
766
- const std::string SVFBasicBlock::toString() const
767
- {
768
- std::string str;
769
- llvm::raw_string_ostream rawstr(str);
770
- auto llvmVal = LLVMModuleSet::getLLVMModuleSet()->getLLVMValue(this);
771
- if (llvmVal)
772
- rawstr << " " << *llvmVal << " ";
773
- else
774
- rawstr << " No llvmVal found";
775
- rawstr << this->getSourceLoc();
776
- return rawstr.str();
777
- }
778
-
779
766
  const std::string SVFValue::valueOnlyToString() const
780
767
  {
781
768
  std::string str;