svf-tools 1.0.957 → 1.0.958

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-tools",
3
- "version": "1.0.957",
3
+ "version": "1.0.958",
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": {
@@ -366,54 +366,6 @@ std::string dumpType(const Type* type);
366
366
 
367
367
  std::string dumpValueAndDbgInfo(const Value* val);
368
368
 
369
- /**
370
- * See more: https://github.com/SVF-tools/SVF/pull/1191
371
- *
372
- * Given the code:
373
- *
374
- * switch (a) {
375
- * case 0: printf("0\n"); break;
376
- * case 1:
377
- * case 2:
378
- * case 3: printf("a >=1 && a <= 3\n"); break;
379
- * case 4:
380
- * case 6:
381
- * case 7: printf("a >= 4 && a <=7\n"); break;
382
- * default: printf("a < 0 || a > 7"); break;
383
- * }
384
- *
385
- * Generate the IR:
386
- *
387
- * switch i32 %0, label %sw.default [
388
- * i32 0, label %sw.bb
389
- * i32 1, label %sw.bb1
390
- * i32 2, label %sw.bb1
391
- * i32 3, label %sw.bb1
392
- * i32 4, label %sw.bb3
393
- * i32 6, label %sw.bb3
394
- * i32 7, label %sw.bb3
395
- * ]
396
- *
397
- * We can get every case basic block and related case value:
398
- * [
399
- * {%sw.default, -1},
400
- * {%sw.bb, 0},
401
- * {%sw.bb1, 1},
402
- * {%sw.bb1, 2},
403
- * {%sw.bb1, 3},
404
- * {%sw.bb3, 4},
405
- * {%sw.bb3, 6},
406
- * {%sw.bb3, 7},
407
- * ]
408
- * Note: default case value is nullptr
409
- */
410
- void getSuccBBandCondValPairVec(const SwitchInst &switchInst, SuccBBAndCondValPairVec &vec);
411
-
412
- /**
413
- * Note: default case value is nullptr
414
- */
415
- s64_t getCaseValue(const SwitchInst &switchInst, SuccBBAndCondValPair &succBB2CondVal);
416
-
417
369
  } // End namespace LLVMUtil
418
370
 
419
371
  } // End namespace SVF
@@ -867,43 +867,6 @@ bool LLVMUtil::isConstantObjSym(const SVFValue* val)
867
867
  }
868
868
 
869
869
 
870
- void LLVMUtil::getSuccBBandCondValPairVec(const SwitchInst &switchInst, SuccBBAndCondValPairVec &vec)
871
- {
872
- // get default successor basic block and default case value (nullptr)
873
- vec.push_back({switchInst.getDefaultDest(), nullptr});
874
-
875
- // get normal case value and it's successor basic block
876
- for (const auto& cs : switchInst.cases())
877
- vec.push_back({cs.getCaseSuccessor(), cs.getCaseValue()});
878
- }
879
-
880
- s64_t LLVMUtil::getCaseValue(const SwitchInst &switchInst, SuccBBAndCondValPair &succBB2CondVal)
881
- {
882
- const BasicBlock* succBB = succBB2CondVal.first;
883
- const ConstantInt* caseValue = succBB2CondVal.second;
884
- s64_t val;
885
- if (caseValue == nullptr || succBB == switchInst.getDefaultDest())
886
- {
887
- /// default case value is set to -1
888
- val = -1;
889
- }
890
- else
891
- {
892
- /// get normal case value
893
- if (caseValue->getBitWidth() <= 64)
894
- {
895
- val = caseValue->getSExtValue();
896
- }
897
- else
898
- {
899
- /// For larger number, we preserve case value just -1 now
900
- /// see more: https://github.com/SVF-tools/SVF/pull/992
901
- val = -1;
902
- }
903
- }
904
- return val;
905
- }
906
-
907
870
  std::string LLVMUtil::dumpValue(const Value* val)
908
871
  {
909
872
  std::string str;
@@ -934,31 +934,82 @@ void SVFIRBuilder::visitBranchInst(BranchInst &inst)
934
934
  assert(inst.getNumSuccessors() <= 2 && "if/else has more than two branches?");
935
935
 
936
936
  BranchStmt::SuccAndCondPairVec successors;
937
- for (u32_t i = 0; i < inst.getNumSuccessors(); ++i)
937
+ std::vector<const Instruction*> nextInsts;
938
+ LLVMUtil::getNextInsts(&inst, nextInsts);
939
+ u32_t branchID = 0;
940
+ for (const Instruction* succInst : nextInsts)
938
941
  {
939
- const Instruction* succInst = &inst.getSuccessor(i)->front();
942
+ assert(branchID <= 2 && "if/else has more than two branches?");
940
943
  const SVFInstruction* svfSuccInst = LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction(succInst);
941
944
  const ICFGNode* icfgNode = pag->getICFG()->getICFGNode(svfSuccInst);
942
- successors.push_back(std::make_pair(icfgNode, 1-i));
945
+ successors.push_back(std::make_pair(icfgNode, 1-branchID));
946
+ branchID++;
943
947
  }
944
- addBranchStmt(brinst, cond,successors);
948
+ addBranchStmt(brinst, cond, successors);
945
949
  }
946
950
 
951
+
952
+ /**
953
+ * See more: https://github.com/SVF-tools/SVF/pull/1191
954
+ *
955
+ * Given the code:
956
+ *
957
+ * switch (a) {
958
+ * case 0: printf("0\n"); break;
959
+ * case 1:
960
+ * case 2:
961
+ * case 3: printf("a >=1 && a <= 3\n"); break;
962
+ * case 4:
963
+ * case 6:
964
+ * case 7: printf("a >= 4 && a <=7\n"); break;
965
+ * default: printf("a < 0 || a > 7"); break;
966
+ * }
967
+ *
968
+ * Generate the IR:
969
+ *
970
+ * switch i32 %0, label %sw.default [
971
+ * i32 0, label %sw.bb
972
+ * i32 1, label %sw.bb1
973
+ * i32 2, label %sw.bb1
974
+ * i32 3, label %sw.bb1
975
+ * i32 4, label %sw.bb3
976
+ * i32 6, label %sw.bb3
977
+ * i32 7, label %sw.bb3
978
+ * ]
979
+ *
980
+ * We can get every case basic block and related case value:
981
+ * [
982
+ * {%sw.default, -1},
983
+ * {%sw.bb, 0},
984
+ * {%sw.bb1, 1},
985
+ * {%sw.bb1, 2},
986
+ * {%sw.bb1, 3},
987
+ * {%sw.bb3, 4},
988
+ * {%sw.bb3, 6},
989
+ * {%sw.bb3, 7},
990
+ * ]
991
+ * Note: default case value is nullptr
992
+ */
993
+ /// For larger number, we preserve case value just -1 now
994
+ /// see more: https://github.com/SVF-tools/SVF/pull/992
995
+
996
+ /// The following implementation follows ICFGBuilder::processFunBody
947
997
  void SVFIRBuilder::visitSwitchInst(SwitchInst &inst)
948
998
  {
949
999
  NodeID brinst = getValueNode(&inst);
950
1000
  NodeID cond = getValueNode(inst.getCondition());
951
1001
 
952
1002
  BranchStmt::SuccAndCondPairVec successors;
953
-
954
- // get case successor basic block and related case value
955
- SuccBBAndCondValPairVec succBB2CondValPairVec;
956
- LLVMUtil::getSuccBBandCondValPairVec(inst, succBB2CondValPairVec);
957
- for (auto &succBB2CaseValue : succBB2CondValPairVec)
1003
+ std::vector<const Instruction*> nextInsts;
1004
+ LLVMUtil::getNextInsts(&inst, nextInsts);
1005
+ for (const Instruction* succInst : nextInsts)
958
1006
  {
959
- s64_t val = LLVMUtil::getCaseValue(inst, succBB2CaseValue);
960
- const BasicBlock *succBB = succBB2CaseValue.first;
961
- const Instruction* succInst = &succBB->front();
1007
+ /// branch condition value
1008
+ const ConstantInt* condVal = inst.findCaseDest(const_cast<BasicBlock*>(succInst->getParent()));
1009
+ /// default case is set to -1;
1010
+ s64_t val = -1;
1011
+ if (condVal && condVal->getBitWidth() <= 64)
1012
+ val = condVal->getSExtValue();
962
1013
  const SVFInstruction* svfSuccInst = LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction(succInst);
963
1014
  const ICFGNode* icfgNode = pag->getICFG()->getICFGNode(svfSuccInst);
964
1015
  successors.push_back(std::make_pair(icfgNode, val));
@@ -966,6 +1017,7 @@ void SVFIRBuilder::visitSwitchInst(SwitchInst &inst)
966
1017
  addBranchStmt(brinst, cond, successors);
967
1018
  }
968
1019
 
1020
+
969
1021
  /// %ap = alloca %struct.va_list
970
1022
  /// %ap2 = bitcast %struct.va_list* %ap to i8*
971
1023
  /// ; Read a single integer argument from %ap2