svf-tools 1.0.987 → 1.0.989

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.
@@ -549,7 +549,6 @@ cJSON* SVFIRWriter::contentToJson(const SVFFunction* value)
549
549
  F(realDefFun);
550
550
  F(allBBs);
551
551
  F(allArgs);
552
- F(annotations);
553
552
  #undef F
554
553
  return root;
555
554
  }
@@ -2357,7 +2356,6 @@ void SVFIRReader::fill(const cJSON*& fieldJson, SVFFunction* value)
2357
2356
  F(realDefFun);
2358
2357
  F(allBBs);
2359
2358
  F(allArgs);
2360
- F(annotations);
2361
2359
  #undef F
2362
2360
  }
2363
2361
 
@@ -161,24 +161,47 @@ std::string ExtAPI::getExtBcPath()
161
161
  abort();
162
162
  }
163
163
 
164
- std::string ExtAPI::getExtFuncAnnotation(const SVFFunction* fun, const std::string& funcAnnotation)
164
+ void ExtAPI::setExtFuncAnnotations(const SVFFunction* fun, const std::vector<std::string>& funcAnnotations)
165
165
  {
166
166
  assert(fun && "Null SVFFunction* pointer");
167
- for (const std::string& annotation : fun->getAnnotations())
168
- if (annotation.find(funcAnnotation) != std::string::npos)
169
- return annotation;
170
- return "";
167
+ func2Annotations[fun] = funcAnnotations;
171
168
  }
172
169
 
173
170
  bool ExtAPI::hasExtFuncAnnotation(const SVFFunction* fun, const std::string& funcAnnotation)
174
171
  {
175
172
  assert(fun && "Null SVFFunction* pointer");
176
- for (const std::string& annotation : fun->getAnnotations())
177
- if (annotation.find(funcAnnotation) != std::string::npos)
178
- return true;
173
+ auto it = func2Annotations.find(fun);
174
+ if (it != func2Annotations.end())
175
+ {
176
+ for (const std::string& annotation : it->second)
177
+ if (annotation.find(funcAnnotation) != std::string::npos)
178
+ return true;
179
+ }
179
180
  return false;
180
181
  }
181
182
 
183
+ std::string ExtAPI::getExtFuncAnnotation(const SVFFunction* fun, const std::string& funcAnnotation)
184
+ {
185
+ assert(fun && "Null SVFFunction* pointer");
186
+ auto it = func2Annotations.find(fun);
187
+ if (it != func2Annotations.end())
188
+ {
189
+ for (const std::string& annotation : it->second)
190
+ if (annotation.find(funcAnnotation) != std::string::npos)
191
+ return annotation;
192
+ }
193
+ return "";
194
+ }
195
+
196
+ const std::vector<std::string>& ExtAPI::getExtFuncAnnotations(const SVFFunction* fun)
197
+ {
198
+ assert(fun && "Null SVFFunction* pointer");
199
+ auto it = func2Annotations.find(fun);
200
+ if (it != func2Annotations.end())
201
+ return it->second;
202
+ return func2Annotations[fun];
203
+ }
204
+
182
205
  bool ExtAPI::is_memcpy(const SVFFunction *F)
183
206
  {
184
207
  return F &&
@@ -232,8 +255,8 @@ bool ExtAPI::is_ext(const SVFFunction* F)
232
255
  assert(F && "Null SVFFunction* pointer");
233
256
  if (F->isDeclaration() || F->isIntrinsic())
234
257
  return true;
235
- else if (hasExtFuncAnnotation(F, "OVERWRITE") && F->getAnnotations().size() == 1)
258
+ else if (hasExtFuncAnnotation(F, "OVERWRITE") && getExtFuncAnnotations(F).size() == 1)
236
259
  return false;
237
260
  else
238
- return !F->getAnnotations().empty();
261
+ return !getExtFuncAnnotations(F).empty();
239
262
  }
@@ -353,13 +353,6 @@ bool SVFUtil::isHeapAllocExtCallViaArg(const CallICFGNode* cs)
353
353
  return isHeapAllocExtFunViaArg(cs->getCalledFunction());
354
354
  }
355
355
 
356
- bool SVFUtil::isHeapAllocExtCallViaArg(const SVFInstruction *inst)
357
- {
358
- if(const SVFCallInst* call = SVFUtil::dyn_cast<SVFCallInst>(inst))
359
- return isHeapAllocExtFunViaArg(call->getCalledFunction());
360
- else
361
- return false;
362
- }
363
356
 
364
357
  u32_t SVFUtil::getHeapAllocHoldingArgPosition(const CallICFGNode* cs)
365
358
  {
@@ -391,14 +384,6 @@ bool SVFUtil::isReallocExtCall(const CallICFGNode* cs)
391
384
  return isPtrTy && isReallocExtFun(cs->getCalledFunction());
392
385
  }
393
386
 
394
- bool SVFUtil::isHeapAllocExtCallViaRet(const SVFInstruction *inst)
395
- {
396
- bool isPtrTy = inst->getType()->isPointerTy();
397
- if(const SVFCallInst* call = SVFUtil::dyn_cast<SVFCallInst>(inst))
398
- return isPtrTy && isHeapAllocExtFunViaRet(call->getCalledFunction());
399
- else
400
- return false;
401
- }
402
387
 
403
388
  bool SVFUtil::isRetInstNode(const ICFGNode* node)
404
389
  {
@@ -61,7 +61,7 @@ public:
61
61
  typedef Map<const SVFValue*, const Value*> SVFValue2LLVMValueMap;
62
62
  typedef Map<const Type*, SVFType*> LLVMType2SVFTypeMap;
63
63
  typedef Map<const Type*, StInfo*> Type2TypeInfoMap;
64
- typedef Map<const Function*, std::vector<std::string>> Fun2AnnoMap;
64
+ typedef Map<std::string, std::vector<std::string>> Fun2AnnoMap;
65
65
 
66
66
  private:
67
67
  static LLVMModuleSet* llvmModuleSet;
@@ -72,10 +72,6 @@ private:
72
72
  std::vector<std::unique_ptr<Module>> owned_modules;
73
73
  std::vector<std::reference_wrapper<Module>> modules;
74
74
 
75
- /// Function declaration to function definition map
76
- FunDeclToDefMapTy FunDeclToDefMap;
77
- /// Function definition to function declaration map
78
- FunDefToDeclsMapTy FunDefToDeclsMap;
79
75
  /// Record some "sse_" function declarations used in other ext function definition, e.g., svf_ext_foo(), and svf_ext_foo() used in app functions
80
76
  FunctionSetType ExtFuncsVec;
81
77
  /// Record annotations of function in extapi.bc
@@ -253,19 +249,6 @@ public:
253
249
 
254
250
  SVFOtherValue* getSVFOtherValue(const Value* ov);
255
251
 
256
- /// Remove unused function in extapi.bc module
257
- bool isCalledExtFunction(Function* func)
258
- {
259
- /// if this function func defined in extapi.bc but never used in application code (without any corresponding declared functions).
260
- if (func->getParent()->getName().str() == ExtAPI::getExtAPI()->getExtBcPath()
261
- && FunDefToDeclsMap.find(func) == FunDefToDeclsMap.end()
262
- && std::find(ExtFuncsVec.begin(), ExtFuncsVec.end(), func) == ExtFuncsVec.end())
263
- {
264
- return true;
265
- }
266
- return false;
267
- }
268
-
269
252
  /// Get the corresponding Function based on its name
270
253
  inline const SVFFunction* getSVFFunction(const std::string& name)
271
254
  {
@@ -283,45 +266,6 @@ public:
283
266
  return nullptr;
284
267
  }
285
268
 
286
- bool hasDefinition(const Function* fun) const
287
- {
288
- assert(fun->isDeclaration() && "not a function declaration?");
289
- FunDeclToDefMapTy::const_iterator it = FunDeclToDefMap.find(fun);
290
- return it != FunDeclToDefMap.end();
291
- }
292
-
293
- const Function* getDefinition(const Function* fun) const
294
- {
295
- assert(fun->isDeclaration() && "not a function declaration?");
296
- FunDeclToDefMapTy::const_iterator it = FunDeclToDefMap.find(fun);
297
- assert(it != FunDeclToDefMap.end() && "has no definition?");
298
- return it->second;
299
- }
300
-
301
- bool hasDeclaration(const Function* fun) const
302
- {
303
- if(fun->isDeclaration() && !hasDefinition(fun))
304
- return false;
305
-
306
- const Function* funDef = fun;
307
- if(fun->isDeclaration() && hasDefinition(fun))
308
- funDef = getDefinition(fun);
309
-
310
- FunDefToDeclsMapTy::const_iterator it = FunDefToDeclsMap.find(funDef);
311
- return it != FunDefToDeclsMap.end();
312
- }
313
-
314
- const FunctionSetType& getDeclaration(const Function* fun) const
315
- {
316
- const Function* funDef = fun;
317
- if(fun->isDeclaration() && hasDefinition(fun))
318
- funDef = getDefinition(fun);
319
-
320
- FunDefToDeclsMapTy::const_iterator it = FunDefToDeclsMap.find(funDef);
321
- assert(it != FunDefToDeclsMap.end() && "does not have a function definition (body)?");
322
- return it->second;
323
- }
324
-
325
269
  /// Global to rep
326
270
  bool hasGlobalRep(const GlobalVariable* val) const
327
271
  {
@@ -400,7 +344,6 @@ private:
400
344
  void prePassSchedule();
401
345
  void buildSymbolTable() const;
402
346
  void collectExtFunAnnotations(const Module* mod);
403
- void removeUnusedExtAPIs();
404
347
  };
405
348
 
406
349
  } // End namespace SVF
@@ -52,8 +52,6 @@ inline bool isCallSite(const Value* val)
52
52
  return SVFUtil::isa<CallBase>(val);
53
53
  }
54
54
 
55
- /// Get the definition of a function across multiple modules
56
- const Function* getDefFunForMultipleModule(const Function* fun);
57
55
 
58
56
  /// Return LLVM callsite given a value
59
57
  inline const CallBase* getLLVMCallSite(const Value* value)
@@ -65,8 +63,7 @@ inline const CallBase* getLLVMCallSite(const Value* value)
65
63
  inline const Function* getCallee(const CallBase* cs)
66
64
  {
67
65
  // FIXME: do we need to strip-off the casts here to discover more library functions
68
- const Function* callee = SVFUtil::dyn_cast<Function>(cs->getCalledOperand()->stripPointerCasts());
69
- return callee ? getDefFunForMultipleModule(callee) : nullptr;
66
+ return SVFUtil::dyn_cast<Function>(cs->getCalledOperand()->stripPointerCasts());
70
67
  }
71
68
 
72
69
  /// Return LLVM function if this value is
@@ -291,9 +288,6 @@ inline static DataLayout* getDataLayout(Module* mod)
291
288
  void getNextInsts(const Instruction* curInst,
292
289
  std::vector<const Instruction*>& instList);
293
290
 
294
- /// Get the previous instructions following control flow
295
- void getPrevInsts(const Instruction* curInst,
296
- std::vector<const Instruction*>& instList);
297
291
 
298
292
  /// Basic block does not have predecessors
299
293
  /// map-1.cpp.bc
@@ -306,9 +300,6 @@ inline bool isNoPrecessorBasicBlock(const BasicBlock* bb)
306
300
  pred_empty(bb);
307
301
  }
308
302
 
309
- /// Get num of BB's predecessors
310
- u32_t getBBPredecessorNum(const BasicBlock* BB);
311
-
312
303
  /// Check whether a file is an LLVM IR file
313
304
  bool isIRFile(const std::string& filename);
314
305
 
@@ -316,10 +307,6 @@ bool isIRFile(const std::string& filename);
316
307
  void processArguments(int argc, char** argv, int& arg_num, char** arg_value,
317
308
  std::vector<std::string>& moduleNameVec);
318
309
 
319
- /// Helper method to get the size of the type from target data layout
320
- //@{
321
- u32_t getTypeSizeInBytes(const Type* type);
322
- u32_t getTypeSizeInBytes(const StructType* sty, u32_t field_index);
323
310
  //@}
324
311
 
325
312
  const std::string getSourceLoc(const Value* val);
@@ -330,11 +317,6 @@ bool isIntrinsicFun(const Function* func);
330
317
 
331
318
  /// Get all called funcions in a parent function
332
319
  std::vector<const Function *> getCalledFunctions(const Function *F);
333
- void removeFunAnnotations(Set<Function*>& removedFuncList);
334
- bool isUnusedGlobalVariable(const GlobalVariable& global);
335
- void removeUnusedGlobalVariables(Module* module);
336
- /// Delete unused functions, annotations and global variables in extapi.bc
337
- void removeUnusedFuncsAndAnnotationsAndGlobalVariables(Set<Function*> removedFuncList);
338
320
  // Converts a mangled name to C naming style to match functions in extapi.c.
339
321
  std::string restoreFuncName(std::string funcName);
340
322
 
@@ -369,6 +351,15 @@ std::string dumpType(const Type* type);
369
351
 
370
352
  std::string dumpValueAndDbgInfo(const Value* val);
371
353
 
354
+ bool isHeapAllocExtCallViaRet(const Instruction *inst);
355
+
356
+ bool isHeapAllocExtCallViaArg(const Instruction *inst);
357
+
358
+ inline bool isHeapAllocExtCall(const Instruction *inst)
359
+ {
360
+ return isHeapAllocExtCallViaRet(inst) || isHeapAllocExtCallViaArg(inst);
361
+ }
362
+
372
363
  } // End namespace LLVMUtil
373
364
 
374
365
  } // End namespace SVF
@@ -71,9 +71,9 @@ void CHGBuilder::buildCHG()
71
71
  for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
72
72
  buildCHGNodes(&(*I));
73
73
  for (Module::const_iterator F = M.begin(), E = M.end(); F != E; ++F)
74
- buildCHGNodes(LLVMUtil::getDefFunForMultipleModule(&(*F)));
74
+ buildCHGNodes(&(*F));
75
75
  for (Module::const_iterator F = M.begin(), E = M.end(); F != E; ++F)
76
- buildCHGEdges(LLVMUtil::getDefFunForMultipleModule(&(*F)));
76
+ buildCHGEdges(&(*F));
77
77
 
78
78
  analyzeVTables(M);
79
79
  }