svf-tools 1.0.702 → 1.0.704

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.
@@ -38,7 +38,7 @@
38
38
  #include "SVF-LLVM/LLVMLoopAnalysis.h"
39
39
  #include "Util/Options.h"
40
40
  #include "SVF-LLVM/CHGBuilder.h"
41
- #include "SVFIR/SVFIRRW.h"
41
+ #include "SVFIR/SVFFileSystem.h"
42
42
  #include "SVF-LLVM/SymbolTableBuilder.h"
43
43
 
44
44
 
@@ -470,7 +470,7 @@ NodeID SVFIRBuilder::getGlobalVarField(const GlobalVariable *gvar, u32_t offset,
470
470
  /// then we need to create a gep node for this field
471
471
  else
472
472
  {
473
- return getGepValVar(gvar, LocationSet(offset), tpy);
473
+ return getGepValVar(LLVMModuleSet::getLLVMModuleSet()->getSVFValue(gvar), LocationSet(offset), tpy);
474
474
  }
475
475
  }
476
476
 
@@ -847,7 +847,9 @@ void SVFIRBuilder::visitCallSite(CallBase* cs)
847
847
  if (isExtCall(svfcallee))
848
848
  {
849
849
  // There is no extpag for the function, use the old method.
850
- handleExtCall(cs, callee);
850
+ preProcessExtCall(cs);
851
+ SVFInstruction* svfinst = LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction(cs);
852
+ handleExtCall(svfinst, svfcallee);
851
853
  }
852
854
  else
853
855
  {
@@ -1154,20 +1156,21 @@ const Type* SVFIRBuilder::getBaseTypeAndFlattenedFields(const Value* V, std::vec
1154
1156
  * Add the load/store constraints and temp. nodes for the complex constraint
1155
1157
  * *D = *S (where D/S may point to structs).
1156
1158
  */
1157
- void SVFIRBuilder::addComplexConsForExt(const Value* D, const Value* S, const Value* szValue)
1159
+ void SVFIRBuilder::addComplexConsForExt(const SVFValue* D, const SVFValue* S, const SVFValue* szValue)
1158
1160
  {
1159
1161
  assert(D && S);
1160
- NodeID vnD= getValueNode(D), vnS= getValueNode(S);
1162
+ NodeID vnD= pag->getValueNode(D), vnS= pag->getValueNode(S);
1161
1163
  if(!vnD || !vnS)
1162
1164
  return;
1163
1165
 
1164
1166
  std::vector<LocationSet> fields;
1165
1167
 
1166
1168
  //Get the max possible size of the copy, unless it was provided.
1167
- std::vector<LocationSet> srcFields;
1168
- std::vector<LocationSet> dstFields;
1169
- const Type* stype = getBaseTypeAndFlattenedFields(S, srcFields, szValue);
1170
- const Type* dtype = getBaseTypeAndFlattenedFields(D, dstFields, szValue);
1169
+ const SVFType* stype = pag->getTypeLocSetsMap(vnS).first;
1170
+ const SVFType* dtype = pag->getTypeLocSetsMap(vnD).first;
1171
+ std::vector<LocationSet> srcFields = pag->getTypeLocSetsMap(vnS).second;
1172
+ std::vector<LocationSet> dstFields = pag->getTypeLocSetsMap(vnD).second;
1173
+
1171
1174
  if(srcFields.size() > dstFields.size())
1172
1175
  fields = dstFields;
1173
1176
  else
@@ -1175,8 +1178,13 @@ void SVFIRBuilder::addComplexConsForExt(const Value* D, const Value* S, const Va
1175
1178
 
1176
1179
  /// If sz is 0, we will add edges for all fields.
1177
1180
  u32_t sz = fields.size();
1181
+ if (szValue && SVFUtil::dyn_cast<SVFConstantInt>(szValue))
1182
+ {
1183
+ const SVFConstantInt* arg2 = SVFUtil::dyn_cast<SVFConstantInt>(szValue);
1184
+ sz = (fields.size() > static_cast<u32_t>(arg2->getSExtValue())) ? arg2->getSExtValue() : fields.size();
1185
+ }
1178
1186
 
1179
- if (fields.size() == 1 && (LLVMUtil::isConstDataOrAggData(D) || LLVMUtil::isConstDataOrAggData(S)))
1187
+ if (fields.size() == 1 && (SVFUtil::isa<SVFConstantData>(D) || SVFUtil::isa<SVFConstantData>(S)))
1180
1188
  {
1181
1189
  NodeID dummy = pag->addDummyValNode();
1182
1190
  addLoadEdge(vnD,dummy);
@@ -1187,10 +1195,9 @@ void SVFIRBuilder::addComplexConsForExt(const Value* D, const Value* S, const Va
1187
1195
  //For each field (i), add (Ti = *S + i) and (*D + i = Ti).
1188
1196
  for (u32_t index = 0; index < sz; index++)
1189
1197
  {
1190
- LLVMModuleSet* llvmmodule = LLVMModuleSet::getLLVMModuleSet();
1191
- const SVFType* dElementType = pag->getSymbolInfo()->getFlatternedElemType(llvmmodule->getSVFType(dtype),
1198
+ const SVFType* dElementType = pag->getSymbolInfo()->getFlatternedElemType(dtype,
1192
1199
  fields[index].getConstantFieldIdx());
1193
- const SVFType* sElementType = pag->getSymbolInfo()->getFlatternedElemType(llvmmodule->getSVFType(stype),
1200
+ const SVFType* sElementType = pag->getSymbolInfo()->getFlatternedElemType(stype,
1194
1201
  fields[index].getConstantFieldIdx());
1195
1202
  NodeID dField = getGepValVar(D,fields[index],dElementType);
1196
1203
  NodeID sField = getGepValVar(S,fields[index],sElementType);
@@ -1200,7 +1207,7 @@ void SVFIRBuilder::addComplexConsForExt(const Value* D, const Value* S, const Va
1200
1207
  }
1201
1208
  }
1202
1209
 
1203
- void SVFIRBuilder::parseOperations(std::vector<ExtAPI::Operation> &operations, CallBase* cs)
1210
+ void SVFIRBuilder::parseOperations(std::vector<ExtAPI::Operation> &operations, const SVFCallInst* svfcall)
1204
1211
  {
1205
1212
  // Record all dummy nodes
1206
1213
  std::map<std::string, NodeID> nodeIDMap;
@@ -1219,7 +1226,7 @@ void SVFIRBuilder::parseOperations(std::vector<ExtAPI::Operation> &operations,
1219
1226
  s32_t nodeIDType = ExtAPI::getExtAPI()->getNodeIDType(s);
1220
1227
  if (nodeIDType >= 0)
1221
1228
  {
1222
- if( cs->arg_size() <= (u32_t) nodeIDType)
1229
+ if( svfcall->arg_size() <= (u32_t) nodeIDType)
1223
1230
  assert(false && "Argument out of bounds!");
1224
1231
  else if (operation.getOperator() == "memcpy_like" || operation.getOperator() == "memset_like")
1225
1232
  {
@@ -1228,14 +1235,14 @@ void SVFIRBuilder::parseOperations(std::vector<ExtAPI::Operation> &operations,
1228
1235
  }
1229
1236
  else
1230
1237
  {
1231
- operands.push_back(getValueNode(cs->getArgOperand(nodeIDType)));
1232
- nodeIDMap[s] = getValueNode(cs->getArgOperand(nodeIDType));
1238
+ operands.push_back(pag->getValueNode(svfcall->getArgOperand(nodeIDType)));
1239
+ nodeIDMap[s] = pag->getValueNode(svfcall->getArgOperand(nodeIDType));
1233
1240
  }
1234
1241
  }
1235
1242
  else if (nodeIDType == -1)
1236
1243
  {
1237
- operands.push_back(getValueNode(cs));
1238
- nodeIDMap[s] = getValueNode(cs);
1244
+ operands.push_back(pag->getValueNode(svfcall));
1245
+ nodeIDMap[s] = pag->getValueNode(svfcall);
1239
1246
  }
1240
1247
  else if (nodeIDType == -2)
1241
1248
  {
@@ -1244,10 +1251,10 @@ void SVFIRBuilder::parseOperations(std::vector<ExtAPI::Operation> &operations,
1244
1251
  }
1245
1252
  else if (nodeIDType == -3)
1246
1253
  {
1247
- if (SVFUtil::isa<PointerType>(cs->getType()))
1254
+ if (svfcall->getType()->isPointerTy())
1248
1255
  {
1249
- operands.push_back(getObjectNode(cs));
1250
- nodeIDMap[s] = getObjectNode(cs);
1256
+ operands.push_back(pag->getObjectNode(svfcall));
1257
+ nodeIDMap[s] = pag->getObjectNode(svfcall);
1251
1258
  }
1252
1259
  }
1253
1260
  else if (nodeIDType == -4)
@@ -1272,21 +1279,87 @@ void SVFIRBuilder::parseOperations(std::vector<ExtAPI::Operation> &operations,
1272
1279
  }
1273
1280
  }
1274
1281
 
1282
+ void SVFIRBuilder::preProcessExtCall(CallBase* cs)
1283
+ {
1284
+ const SVFInstruction* svfinst = LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction(cs);
1285
+ const SVFCallInst* svfcall = SVFUtil::cast<SVFCallInst>(svfinst);
1286
+ /// Currently focusing on providing specialized treatment for the extern function void *dlsym(void *handle, const char *funname)
1287
+ /// and generalization will be done later.
1288
+ if (svfcall->getCalledFunction()->getName() == "dlsym")
1289
+ {
1290
+ const Value* src = cs->getArgOperand(1);
1291
+ if(const GetElementPtrInst* gep = SVFUtil::dyn_cast<GetElementPtrInst>(src))
1292
+ src = stripConstantCasts(gep->getPointerOperand());
1293
+
1294
+ auto getHookFn = [](const Value* src)->const Function*
1295
+ {
1296
+ if (!SVFUtil::isa<GlobalVariable>(src))
1297
+ return nullptr;
1298
+
1299
+ auto *glob = SVFUtil::cast<GlobalVariable>(src);
1300
+ if (!glob->hasInitializer() || !SVFUtil::isa<ConstantDataArray>(glob->getInitializer()))
1301
+ return nullptr;
1302
+
1303
+ auto *constarray = SVFUtil::cast<ConstantDataArray>(glob->getInitializer());
1304
+ return LLVMUtil::getProgFunction(constarray->getAsCString().str());
1305
+ };
1306
+
1307
+ if (const Function *fn = getHookFn(src))
1308
+ {
1309
+ NodeID srcNode = getValueNode(fn);
1310
+ addCopyEdge(srcNode, getValueNode(cs));
1311
+ }
1312
+ return;
1313
+ }
1314
+ /// Preprocess the arguments of functions such as memset() and memcpy() that involve arrays or structures,
1315
+ /// and identify the original data types of these arguments, flattening each subfield.
1316
+ if (isMemSetOrCpyExtFun(svfcall->getCalledFunction()))
1317
+ {
1318
+ for (u32_t i = 0; i < cs->arg_size(); i++)
1319
+ {
1320
+ const Type* T = getBaseValueForExtArg(cs->getArgOperand(i))->getType();
1321
+ while (const PointerType *ptype = SVFUtil::dyn_cast<PointerType>(T))
1322
+ T = getPtrElementType(ptype);
1323
+ const SVFType *st = LLVMModuleSet::getLLVMModuleSet()->getSVFType(T);
1324
+ std::vector<LocationSet> fields;
1325
+ u32_t numOfElems = pag->getSymbolInfo()->getNumOfFlattenElements(st);
1326
+ LLVMContext& context = LLVMModuleSet::getLLVMModuleSet()->getContext();
1327
+ for(u32_t ei = 0; ei < numOfElems; ei++)
1328
+ {
1329
+ LocationSet ls(ei);
1330
+ // make a ConstantInt and create char for the content type due to byte-wise copy
1331
+ const ConstantInt* offset = ConstantInt::get(context, llvm::APInt(32, ei));
1332
+ const SVFValue* svfOffset = LLVMModuleSet::getLLVMModuleSet()->getSVFValue(offset);
1333
+ if (!pag->getSymbolInfo()->hasValSym(svfOffset))
1334
+ {
1335
+ SymbolTableBuilder builder(pag->getSymbolInfo());
1336
+ builder.collectSym(offset);
1337
+ pag->addValNode(svfOffset, pag->getSymbolInfo()->getValSym(svfOffset));
1338
+ }
1339
+ ls.addOffsetVarAndGepTypePair(getPAG()->getGNode(getPAG()->getValueNode(svfOffset)), nullptr);
1340
+ fields.push_back(ls);
1341
+ }
1342
+ NodeID argId = pag->getValueNode(svfcall->getArgOperand(i));
1343
+ std::pair<const SVFType*, std::vector<LocationSet>> pairToInsert = std::make_pair(st, fields);
1344
+ pag->addToTypeLocSetsMap(argId, pairToInsert);
1345
+ }
1346
+ }
1347
+ }
1348
+
1275
1349
  /*!
1276
1350
  * Handle external calls
1277
1351
  */
1278
- void SVFIRBuilder::handleExtCall(CallBase* cs, const Function *callee)
1352
+ void SVFIRBuilder::handleExtCall(SVFInstruction* svfinst, const SVFFunction* svfcallee)
1279
1353
  {
1280
- const SVFInstruction* svfinst = LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction(cs);
1281
- const SVFFunction* svfcallee = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(callee);
1354
+ const SVFCallInst* svfcall = SVFUtil::cast<SVFCallInst>(svfinst);
1282
1355
 
1283
1356
  if (isHeapAllocOrStaticExtCall(svfinst))
1284
1357
  {
1285
1358
  // case 1: ret = new obj
1286
1359
  if (isHeapAllocExtCallViaRet(svfinst) || isStaticExtCall(svfinst))
1287
1360
  {
1288
- NodeID val = getValueNode(cs);
1289
- NodeID obj = getObjectNode(cs);
1361
+ NodeID val = pag->getValueNode(svfinst);
1362
+ NodeID obj = pag->getObjectNode(svfinst);
1290
1363
  addAddrEdge(obj, val);
1291
1364
  }
1292
1365
  // case 2: *arg = new obj
@@ -1294,12 +1367,12 @@ void SVFIRBuilder::handleExtCall(CallBase* cs, const Function *callee)
1294
1367
  {
1295
1368
  assert(isHeapAllocExtCallViaArg(svfinst) && "Must be heap alloc call via arg.");
1296
1369
  u32_t arg_pos = getHeapAllocHoldingArgPosition(svfcallee);
1297
- const Value* arg = cs->getArgOperand(arg_pos);
1370
+ const SVFValue* arg = svfcall->getArgOperand(arg_pos);
1298
1371
  if (arg->getType()->isPointerTy())
1299
1372
  {
1300
- NodeID vnArg = getValueNode(arg);
1373
+ NodeID vnArg = pag->getValueNode(arg);
1301
1374
  NodeID dummy = pag->addDummyValNode();
1302
- NodeID obj = pag->addDummyObjNode(LLVMModuleSet::getLLVMModuleSet()->getSVFType(arg->getType()));
1375
+ NodeID obj = pag->addDummyObjNode(arg->getType());
1303
1376
  if (vnArg && dummy && obj)
1304
1377
  {
1305
1378
  addAddrEdge(obj, dummy);
@@ -1322,12 +1395,12 @@ void SVFIRBuilder::handleExtCall(CallBase* cs, const Function *callee)
1322
1395
  {
1323
1396
  std::string str;
1324
1397
  std::stringstream rawstr(str);
1325
- rawstr << "function " << callee->getName().str() << " not in the external function summary ExtAPI.json file";
1398
+ rawstr << "function " << funName << " not in the external function summary ExtAPI.json file";
1326
1399
  writeWrnMsg(rawstr.str());
1327
1400
  }
1328
1401
  else
1329
1402
  {
1330
- parseOperations(allOperations, cs);
1403
+ parseOperations(allOperations, svfcall);
1331
1404
  for (ExtAPI::Operation op : allOperations)
1332
1405
  {
1333
1406
  if (op.getOperator() == "AddrStmt")
@@ -1393,69 +1466,40 @@ void SVFIRBuilder::handleExtCall(CallBase* cs, const Function *callee)
1393
1466
  {
1394
1467
  // this is for memset(void *str, int c, size_t n)
1395
1468
  // which copies the character c (an unsigned char) to the first n characters of the string pointed to, by the argument str
1396
- std::vector<LocationSet> dstFields;
1397
- const Type* dtype = getBaseTypeAndFlattenedFields(cs->getArgOperand(op.getOperands()[0]), dstFields, cs->getArgOperand(op.getOperands()[2]));
1469
+ // const SVFConstantInt* arg2 = SVFUtil::dyn_cast<SVFConstantInt>(svfcall->getArgOperand(op.getOperands()[2]));
1470
+ NodeID argId = pag->getValueNode(svfcall->getArgOperand(op.getOperands()[0]));
1471
+ std::vector<LocationSet> dstFields = pag->getTypeLocSetsMap(argId).second;
1398
1472
  u32_t sz = dstFields.size();
1473
+ if (const SVFConstantInt* arg2 = SVFUtil::dyn_cast<SVFConstantInt>(svfcall->getArgOperand(op.getOperands()[2])))
1474
+ sz = (dstFields.size() > static_cast<u32_t>(arg2->getSExtValue())) ? arg2->getSExtValue() : dstFields.size();
1399
1475
  //For each field (i), add store edge *(arg0 + i) = arg1
1400
1476
  for (u32_t index = 0; index < sz; index++)
1401
1477
  {
1402
- const SVFType* dElementType = pag->getSymbolInfo()->getFlatternedElemType(LLVMModuleSet::getLLVMModuleSet()->getSVFType(dtype),
1403
- dstFields[index].getConstantFieldIdx());
1404
- NodeID dField = getGepValVar(cs->getArgOperand(op.getOperands()[0]), dstFields[index], dElementType);
1405
- addStoreEdge(getValueNode(cs->getArgOperand(op.getOperands()[1])),dField);
1478
+ const SVFType* dElementType = pag->getSymbolInfo()->getFlatternedElemType(pag->getTypeLocSetsMap(argId).first, dstFields[index].getConstantFieldIdx());
1479
+ NodeID dField = getGepValVar(svfcall->getArgOperand(op.getOperands()[0]), dstFields[index], dElementType);
1480
+ addStoreEdge(pag->getValueNode(svfcall->getArgOperand(op.getOperands()[1])),dField);
1406
1481
  }
1407
- if(SVFUtil::isa<PointerType>(cs->getType()))
1408
- addCopyEdge(getValueNode(cs->getArgOperand(op.getOperands()[0])), getValueNode(cs));
1482
+ if(svfcall->getType()->isPointerTy())
1483
+ addCopyEdge(pag->getValueNode(svfcall->getArgOperand(op.getOperands()[0])), pag->getValueNode(svfinst));
1409
1484
  }
1410
1485
  else if (op.getOperator() == "memcpy_like")
1411
1486
  {
1412
- /// handle strcpy
1413
1487
  if(op.getOperands().size() == 3)
1414
- addComplexConsForExt(cs->getArgOperand(op.getOperands()[0]), cs->getArgOperand(op.getOperands()[1]), cs->getArgOperand(op.getOperands()[2]));
1488
+ addComplexConsForExt(svfcall->getArgOperand(op.getOperands()[0]), svfcall->getArgOperand(op.getOperands()[1]), svfcall->getArgOperand(op.getOperands()[2]));
1415
1489
  else
1416
- addComplexConsForExt(cs->getArgOperand(op.getOperands()[0]), cs->getArgOperand(op.getOperands()[1]), nullptr);
1417
- }
1418
- else if (op.getOperator() == "funptr_ops")
1419
- {
1420
- /// handling external function e.g., void *dlsym(void *handle, const char *funname);
1421
- const Value* src = cs->getArgOperand(1);
1422
- if(const GetElementPtrInst* gep = SVFUtil::dyn_cast<GetElementPtrInst>(src))
1423
- src = stripConstantCasts(gep->getPointerOperand());
1424
-
1425
- auto getHookFn = [](const Value* src)->const Function*
1426
- {
1427
- if (!SVFUtil::isa<GlobalVariable>(src))
1428
- return nullptr;
1429
-
1430
- auto *glob = SVFUtil::cast<GlobalVariable>(src);
1431
- if (!glob->hasInitializer() || !SVFUtil::isa<ConstantDataArray>(glob->getInitializer()))
1432
- return nullptr;
1433
-
1434
- auto *constarray = SVFUtil::cast<ConstantDataArray>(glob->getInitializer());
1435
- return LLVMUtil::getProgFunction(constarray->getAsCString().str());
1436
- };
1437
-
1438
- if (const Function *fn = getHookFn(src))
1439
- {
1440
- NodeID srcNode = getValueNode(fn);
1441
- addCopyEdge(srcNode, getValueNode(cs));
1442
- }
1490
+ addComplexConsForExt(svfcall->getArgOperand(op.getOperands()[0]), svfcall->getArgOperand(op.getOperands()[1]), nullptr);
1443
1491
  }
1444
1492
  else if (op.getOperator() == "Rb_tree_ops")
1445
1493
  {
1446
- assert(cs->arg_size() == 4 && "_Rb_tree_insert_and_rebalance should have 4 arguments.\n");
1447
-
1448
- const Value* vArg1 = cs->getArgOperand(1);
1449
- const Value* vArg3 = cs->getArgOperand(3);
1494
+ assert(svfcall->arg_size() == 4 && "_Rb_tree_insert_and_rebalance should have 4 arguments.\n");
1450
1495
 
1451
1496
  // We have vArg3 points to the entry of _Rb_tree_node_base { color; parent; left; right; }.
1452
1497
  // Now we calculate the offset from base to vArg3
1453
- NodeID vnArg3 = pag->getValueNode(LLVMModuleSet::getLLVMModuleSet()->getSVFValue(vArg3));
1498
+ NodeID vnArg3 = pag->getValueNode(svfcall->getArgOperand(3));
1454
1499
  s32_t offset = getLocationSetFromBaseNode(vnArg3).getConstantFieldIdx();
1455
1500
 
1456
1501
  // We get all flattened fields of base
1457
- vector<LocationSet> fields;
1458
- const Type* type = getBaseTypeAndFlattenedFields(vArg3, fields, nullptr);
1502
+ vector<LocationSet> fields = pag->getTypeLocSetsMap(vnArg3).second;
1459
1503
 
1460
1504
  // We summarize the side effects: arg3->parent = arg1, arg3->left = arg1, arg3->right = arg1
1461
1505
  // Note that arg0 is aligned with "offset".
@@ -1463,10 +1507,10 @@ void SVFIRBuilder::handleExtCall(CallBase* cs, const Function *callee)
1463
1507
  {
1464
1508
  if((u32_t)i >= fields.size())
1465
1509
  break;
1466
- const SVFType* elementType = pag->getSymbolInfo()->getFlatternedElemType(LLVMModuleSet::getLLVMModuleSet()->getSVFType(type),
1510
+ const SVFType* elementType = pag->getSymbolInfo()->getFlatternedElemType(pag->getTypeLocSetsMap(vnArg3).first,
1467
1511
  fields[i].getConstantFieldIdx());
1468
- NodeID vnD = getGepValVar(vArg3, fields[i], elementType);
1469
- NodeID vnS = getValueNode(vArg1);
1512
+ NodeID vnD = getGepValVar(svfcall->getArgOperand(3), fields[i], elementType);
1513
+ NodeID vnS = pag->getValueNode(svfcall->getArgOperand(1));
1470
1514
  if(vnD && vnS)
1471
1515
  addStoreEdge(vnS,vnD);
1472
1516
  }
@@ -1574,7 +1618,9 @@ void SVFIRBuilder::updateCallGraph(PTACallGraph* callgraph)
1574
1618
  if (isExtCall(*func_iter))
1575
1619
  {
1576
1620
  setCurrentLocation(callee, callee->empty() ? nullptr : &callee->getEntryBlock());
1577
- handleExtCall(const_cast<CallBase*>(callbase), callee);
1621
+ SVFInstruction* svfinst = LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction(callbase);
1622
+ const SVFFunction* svfcallee = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(callee);
1623
+ handleExtCall(svfinst, svfcallee);
1578
1624
  }
1579
1625
  else
1580
1626
  {
@@ -1618,9 +1664,9 @@ void SVFIRBuilder::sanityCheck()
1618
1664
  * Add a temp field value node according to base value and offset
1619
1665
  * this node is after the initial node method, it is out of scope of symInfo table
1620
1666
  */
1621
- NodeID SVFIRBuilder::getGepValVar(const Value* val, const LocationSet& ls, const SVFType* elementType)
1667
+ NodeID SVFIRBuilder::getGepValVar(const SVFValue* val, const LocationSet& ls, const SVFType* elementType)
1622
1668
  {
1623
- NodeID base = pag->getBaseValVar(getValueNode(val));
1669
+ NodeID base = pag->getBaseValVar(pag->getValueNode(val));
1624
1670
  NodeID gepval = pag->getGepValVar(curVal, base, ls);
1625
1671
  if (gepval==UINT_MAX)
1626
1672
  {
@@ -1640,8 +1686,7 @@ NodeID SVFIRBuilder::getGepValVar(const Value* val, const LocationSet& ls, const
1640
1686
  const SVFValue* cval = getCurrentValue();
1641
1687
  const SVFBasicBlock* cbb = getCurrentBB();
1642
1688
  setCurrentLocation(curVal, nullptr);
1643
- LLVMModuleSet* llvmmodule = LLVMModuleSet::getLLVMModuleSet();
1644
- NodeID gepNode= pag->addGepValNode(curVal, llvmmodule->getSVFValue(val),ls, NodeIDAllocator::get()->allocateValueId(),elementType->getPointerTo());
1689
+ NodeID gepNode= pag->addGepValNode(curVal, val,ls, NodeIDAllocator::get()->allocateValueId(),elementType->getPointerTo());
1645
1690
  addGepEdge(base, gepNode, ls, true);
1646
1691
  setCurrentLocation(cval, cbb);
1647
1692
  return gepNode;
@@ -30,7 +30,7 @@
30
30
  #include "SVF-LLVM/SVFIRBuilder.h"
31
31
  #include "Util/CommandLine.h"
32
32
  #include "Util/Options.h"
33
- #include "SVFIR/SVFIRRW.h"
33
+ #include "SVFIR/SVFFileSystem.h"
34
34
 
35
35
 
36
36
  using namespace std;
@@ -31,7 +31,7 @@
31
31
  #include "WPA/WPAPass.h"
32
32
  #include "Util/CommandLine.h"
33
33
  #include "Util/Options.h"
34
- #include "SVFIR/SVFIRRW.h"
34
+ #include "SVFIR/SVFFileSystem.h"
35
35
 
36
36
 
37
37
  using namespace llvm;
@@ -1,197 +0,0 @@
1
- //===- SVFModuleRW.h -- SVFModuleReader* class--------------------------------//
2
- //
3
- // SVF: Static Value-Flow Analysis
4
- //
5
- // Copyright (C) <2013-2017> <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
- * SVFModuleRW.h
25
- *
26
- * Created on: 27 Jan 2023
27
- * Author: Xudong Wang
28
- */
29
-
30
- #ifndef INCLUDE_SVFMODULE_JSON_DUMPER_H_
31
- #define INCLUDE_SVFMODULE_JSON_DUMPER_H_
32
-
33
- #include <string>
34
- #include <vector>
35
- #include <unordered_map>
36
- #include <ostream>
37
- #include <memory>
38
-
39
- struct cJSON;
40
-
41
- namespace SVF
42
- {
43
- class SVFModule;
44
-
45
- class StInfo;
46
- class SVFType;
47
- class SVFPointerType;
48
- class SVFIntegerType;
49
- class SVFFunctionType;
50
- class SVFStructType;
51
- class SVFArrayType;
52
- class SVFOtherType;
53
-
54
- class SVFLoopAndDomInfo;
55
- class SVFValue;
56
- class SVFFunction;
57
- class SVFBasicBlock;
58
- class SVFInstruction;
59
- class SVFCallInst;
60
- class SVFVirtualCallInst;
61
- class SVFConstant;
62
- class SVFGlobalValue;
63
- class SVFArgument;
64
- class SVFConstantData;
65
- class SVFConstantInt;
66
- class SVFConstantFP;
67
- class SVFConstantNullPtr;
68
- class SVFBlackHoleValue;
69
- class SVFOtherValue;
70
- class SVFMetadataAsValue;
71
-
72
- using TypeIndex = std::size_t;
73
- using ValueIndex = std::size_t;
74
-
75
- class SVFModuleWrite
76
- {
77
- private:
78
- const SVFModule* module; ///< Borrowed pointer to the SVFModule.
79
- const char* jsonStr; ///< Json string of the SVFModule. It gets freed by `cJSON_free()` in destructor.
80
-
81
- std::unordered_map<const SVFType*, TypeIndex> typeToIndex;
82
- std::vector<const SVFType*> typePool; ///< A pool of all SVFTypes in the SVFModule
83
- TypeIndex getTypeIndex(const SVFType* type);
84
- const char* getStrTypeIndex(const SVFType* type);
85
-
86
- std::unordered_map<const SVFValue*, ValueIndex> valueToIndex;
87
- std::vector<const SVFValue*> valuePool; ///< A pool of all SVFValues in the SVFModule
88
- ValueIndex getValueIndex(const SVFValue* value);
89
- const char* getStrValueIndex(const SVFValue* value);
90
-
91
- std::vector<std::unique_ptr<std::string>> allIndices;
92
- const char* getStrOfIndex(std::size_t index);
93
-
94
- public:
95
- SVFModuleWrite(const SVFModule* module);
96
- /// @brief Dump the SVFModule to a file in JSON format at the given path.
97
- SVFModuleWrite(const SVFModule* module, const std::string& path);
98
- void dumpJsonToPath(const std::string& path);
99
- void dumpJsonToOstream(std::ostream& os);
100
- ~SVFModuleWrite();
101
-
102
- private:
103
- cJSON* moduleToJson(const SVFModule* module);
104
-
105
- cJSON* typeToJson(const SVFType* type);
106
- cJSON* toJson(const StInfo* stInfo);
107
- // SVFType and all its descendants/subclasses.
108
- cJSON* toJson(const SVFType* type);
109
- cJSON* toJson(const SVFPointerType* type);
110
- cJSON* toJson(const SVFIntegerType* type);
111
- cJSON* toJson(const SVFFunctionType* type);
112
- cJSON* toJson(const SVFStructType* type);
113
- cJSON* toJson(const SVFArrayType* type);
114
- cJSON* toJson(const SVFOtherType* type);
115
-
116
- cJSON* valueToJson(const SVFValue* value);
117
- cJSON* toJson(const SVFLoopAndDomInfo* ldInfo);
118
- // SVFValue and all its descendants/subclasses.
119
- cJSON* toJson(const SVFValue* value);
120
- cJSON* toJson(const SVFFunction* value);
121
- cJSON* toJson(const SVFBasicBlock* value);
122
- cJSON* toJson(const SVFInstruction* value);
123
- cJSON* toJson(const SVFCallInst* value);
124
- cJSON* toJson(const SVFVirtualCallInst* value);
125
- cJSON* toJson(const SVFConstant* value);
126
- cJSON* toJson(const SVFGlobalValue* value);
127
- cJSON* toJson(const SVFArgument* value);
128
- cJSON* toJson(const SVFConstantData* value);
129
- cJSON* toJson(const SVFConstantInt* value);
130
- cJSON* toJson(const SVFConstantFP* value);
131
- cJSON* toJson(const SVFConstantNullPtr* value);
132
- cJSON* toJson(const SVFBlackHoleValue* value);
133
- cJSON* toJson(const SVFOtherValue* value);
134
- cJSON* toJson(const SVFMetadataAsValue* value);
135
- };
136
-
137
- class SVFModuleRead
138
- {
139
- private:
140
- cJSON* moduleJson; ///< Owned pointer to the root object of the SVFModule. Be
141
- ///< sure to delete it with `cJSON_Delete()` it in
142
- ///< destructor.
143
-
144
- SVFModule* svfModule;
145
-
146
- std::vector<SVFType*> typePool; ///< A pool of all SVFTypes in the SVFModule
147
- std::vector<cJSON*> typeArray;
148
-
149
- std::vector<SVFValue*>
150
- valuePool; ///< A pool of all SVFValues in the SVFModule
151
- std::vector<cJSON*> valueArray;
152
-
153
- public:
154
- SVFModule* get();
155
- SVFModuleRead(const std::string& path);
156
- ~SVFModuleRead();
157
-
158
- private:
159
- SVFModule* readSvfModule(cJSON* iter);
160
-
161
- SVFType* indexToType(TypeIndex i);
162
- SVFValue* indexToValue(ValueIndex i);
163
-
164
- void fillSVFTypeAt(size_t i);
165
- void fillSVFValueAt(size_t i);
166
-
167
- StInfo* readStInfo(cJSON* iter);
168
- cJSON* readJson(cJSON* iter, SVFType* type);
169
- cJSON* readJson(cJSON* iter, SVFPointerType* type);
170
- cJSON* readJson(cJSON* iter, SVFIntegerType* type);
171
- cJSON* readJson(cJSON* iter, SVFFunctionType* type);
172
- cJSON* readJson(cJSON* iter, SVFStructType* type);
173
- cJSON* readJson(cJSON* iter, SVFArrayType* type);
174
- cJSON* readJson(cJSON* iter, SVFOtherType* type);
175
-
176
- SVFLoopAndDomInfo* readSvfLoopAndDomInfo(cJSON* iter);
177
- cJSON* readJson(cJSON* iter, SVFValue* value);
178
- cJSON* readJson(cJSON* iter, SVFFunction* value);
179
- cJSON* readJson(cJSON* iter, SVFBasicBlock* value);
180
- cJSON* readJson(cJSON* iter, SVFInstruction* value);
181
- cJSON* readJson(cJSON* iter, SVFCallInst* value);
182
- cJSON* readJson(cJSON* iter, SVFVirtualCallInst* value);
183
- cJSON* readJson(cJSON* iter, SVFConstant* value);
184
- cJSON* readJson(cJSON* iter, SVFGlobalValue* value);
185
- cJSON* readJson(cJSON* iter, SVFArgument* value);
186
- cJSON* readJson(cJSON* iter, SVFConstantData* value);
187
- cJSON* readJson(cJSON* iter, SVFConstantInt* value);
188
- cJSON* readJson(cJSON* iter, SVFConstantFP* value);
189
- cJSON* readJson(cJSON* iter, SVFConstantNullPtr* value);
190
- cJSON* readJson(cJSON* iter, SVFBlackHoleValue* value);
191
- cJSON* readJson(cJSON* iter, SVFOtherValue* value);
192
- cJSON* readJson(cJSON* iter, SVFMetadataAsValue* value);
193
- };
194
-
195
- } // namespace SVF
196
-
197
- #endif // !INCLUDE_SVFMODULE_JSON_DUMPER_H_