Static Value-Flow Analysis
Classes | Typedefs | Functions | Variables
SVF::SVFUtil Namespace Reference

Classes

struct  add_const_past_pointer
 
struct  add_const_past_pointer< T, std::enable_if_t< std::is_pointer< T >::value > >
 
struct  add_lvalue_reference_if_not_pointer
 If T is a pointer, just return it. If it is not, return T&. More...
 
struct  add_lvalue_reference_if_not_pointer< T, std::enable_if_t< std::is_pointer< T >::value > >
 
struct  simplify_type
 
struct  simplify_type< const From >
 
struct  isa_impl
 
struct  isa_impl< To, From, std::enable_if_t< std::is_base_of< To, From >::value > >
 Always allow upcasts, and perform no dynamic check for them. More...
 
struct  isa_impl_cl
 
struct  isa_impl_cl< To, const From >
 
struct  isa_impl_cl< To, const std::unique_ptr< From > >
 
struct  isa_impl_cl< To, From * >
 
struct  isa_impl_cl< To, From *const >
 
struct  isa_impl_cl< To, const From * >
 
struct  isa_impl_cl< To, const From *const >
 
struct  isa_impl_wrap
 
struct  isa_impl_wrap< To, FromTy, FromTy >
 
struct  cast_retty
 
struct  cast_retty_impl
 
struct  cast_retty_impl< To, const From >
 
struct  cast_retty_impl< To, From * >
 
struct  cast_retty_impl< To, const From * >
 
struct  cast_retty_impl< To, const From *const >
 
struct  cast_retty_impl< To, std::unique_ptr< From > >
 
struct  cast_retty_wrap
 
struct  cast_retty_wrap< To, FromTy, FromTy >
 
struct  cast_convert_val
 
struct  cast_convert_val< To, FromTy, FromTy >
 
struct  is_simple_type
 
struct  equalPointsTo
 
struct  equalNodeBS
 
struct  make_void
 void_t is not available until C++17. We define it here for C++11/14. More...
 
struct  is_iterable
 Type trait that checks if a type is iterable (can be applied on a range-based for loop) More...
 
struct  is_iterable< T, void_t< decltype(std::begin(std::declval< T & >()) !=std::end(std::declval< T & >()))> >
 
struct  is_map
 Type trait to check if a type is a map or unordered_map. More...
 
struct  is_map< std::map< Ts... > >
 
struct  is_map< std::unordered_map< Ts... > >
 
struct  is_set
 Type trait to check if a type is a set or unordered_set. More...
 
struct  is_set< std::set< Ts... > >
 
struct  is_set< std::unordered_set< Ts... > >
 
struct  is_sequence_container
 Type trait to check if a type is vector or list. More...
 
struct  is_sequence_container< std::vector< Ts... > >
 
struct  is_sequence_container< std::deque< Ts... > >
 
struct  is_sequence_container< std::list< Ts... > >
 

Typedefs

typedef struct SVF::SVFUtil::equalPointsTo equalPointsTo
 
typedef struct SVF::SVFUtil::equalNodeBS equalNodeBS
 
typedef OrderedSet< PointsTo, equalPointsToPointsToList
 

Functions

template<class X , class Y >
LLVM_NODISCARD bool isa (const Y &Val)
 
template<typename First , typename Second , typename... Rest, typename Y >
LLVM_NODISCARD bool isa (const Y &Val)
 
template<class X , class Y >
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast (const Y &Val)
 
template<class X , class Y >
cast_retty< X, Y >::ret_type cast (Y &Val)
 
template<class X , class Y >
cast_retty< X, Y * >::ret_type cast (Y *Val)
 
template<class X , class Y >
cast_retty< X, std::unique_ptr< Y > >::ret_type cast (std::unique_ptr< Y > &&Val)
 
template<class X , class Y >
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast (const Y &Val)
 
template<class X , class Y >
LLVM_NODISCARD cast_retty< X, Y >::ret_type dyn_cast (Y &Val)
 
template<class X , class Y >
LLVM_NODISCARD cast_retty< X, Y * >::ret_type dyn_cast (Y *Val)
 
std::ostream & outs ()
 Overwrite llvm::outs() More...
 
std::ostream & errs ()
 Overwrite llvm::errs() More...
 
void dumpSet (NodeBS To, OutStream &O=SVFUtil::outs())
 Dump sparse bitvector set. More...
 
void dumpSet (PointsTo To, OutStream &O=SVFUtil::outs())
 
void dumpPointsToSet (unsigned node, NodeBS To)
 Dump points-to set. More...
 
void dumpSparseSet (const NodeBS &To)
 
void dumpAliasSet (unsigned node, NodeBS To)
 Dump alias set. More...
 
std::string sucMsg (const std::string &msg)
 Returns successful message by converting a string into green string output. More...
 
std::string wrnMsg (const std::string &msg)
 Returns warning message by converting a string into yellow string output. More...
 
void writeWrnMsg (const std::string &msg)
 Writes a message run through wrnMsg. More...
 
std::string errMsg (const std::string &msg)
 Print error message by converting a string into red string output. More...
 
std::string bugMsg1 (const std::string &msg)
 
std::string bugMsg2 (const std::string &msg)
 
std::string bugMsg3 (const std::string &msg)
 
std::string pasMsg (const std::string &msg)
 Print each pass/phase message by converting a string into blue string output. More...
 
void reportMemoryUsageKB (const std::string &infor, OutStream &O=SVFUtil::outs())
 Print memory usage in KB. More...
 
bool getMemoryUsageKB (u32_t *vmrss_kb, u32_t *vmsize_kb)
 Get memory usage from system file. Return TRUE if succeed. More...
 
void increaseStackSize ()
 Increase the stack size limit. More...
 
bool cmpPts (const PointsTo &lpts, const PointsTo &rpts)
 
bool cmpNodeBS (const NodeBS &lpts, const NodeBS &rpts)
 
NodeBS ptsToNodeBS (const PointsTo &pts)
 
void dumpPointsToList (const PointsToList &ptl)
 
bool isIntrinsicInst (const SVFInstruction *inst)
 Return true if it is an llvm intrinsic instruction. More...
 
bool isIntrinsicInst (const ICFGNode *inst)
 
bool isCallSite (const SVFValue *val)
 Whether an instruction is a call or invoke instruction. More...
 
bool isCallSite (const ICFGNode *inst)
 
bool isRetInstNode (const ICFGNode *node)
 
bool isNonInstricCallSite (const ICFGNode *inst)
 Whether an instruction is a callsite in the application code, excluding llvm intrinsic calls. More...
 
bool matchArgs (const CallICFGNode *cs, const SVFFunction *callee)
 
std::vector< std::stringsplit (const std::string &s, char separator)
 Split into two substrings around the first occurrence of a separator string. More...
 
template<typename Data >
void mergePtsOccMaps (Map< Data, unsigned > &to, const Map< Data, unsigned > from)
 Given a map mapping points-to sets to a count, adds from into to. More...
 
std::string hclustMethodToString (hclust_fast_methods method)
 Returns a string representation of a hclust method. More...
 
template<typename Key , typename KeySet >
void insertKey (const Key &key, KeySet &keySet)
 Inserts an element into a Set/CondSet (with ::insert). More...
 
void insertKey (const NodeID &key, NodeBS &keySet)
 Inserts a NodeID into a NodeBS. More...
 
template<typename Key , typename KeySet >
void removeKey (const Key &key, KeySet &keySet)
 Removes an element from a Set/CondSet (or anything implementing ::erase). More...
 
void removeKey (const NodeID &key, NodeBS &keySet)
 Removes a NodeID from a NodeBS. More...
 
void timeLimitReached (int signum)
 Function to call when alarm for time limit hits. More...
 
bool startAnalysisLimitTimer (unsigned timeLimit)
 
void stopAnalysisLimitTimer (bool limitTimerSet)
 
bool isExtCall (const SVFFunction *fun)
 
bool isMemcpyExtFun (const SVFFunction *fun)
 
bool isMemsetExtFun (const SVFFunction *fun)
 
bool isHeapAllocExtFunViaRet (const SVFFunction *fun)
 Return true if the call is a heap allocator/reallocator. More...
 
bool isHeapAllocExtFunViaArg (const SVFFunction *fun)
 
u32_t getHeapAllocHoldingArgPosition (const SVFFunction *fun)
 Get the position of argument that holds an allocated heap object. More...
 
bool isReallocExtFun (const SVFFunction *fun)
 Return true if the call is a heap reallocator. More...
 
bool isProgEntryFunction (const SVFFunction *fun)
 Program entry function e.g. main. More...
 
const SVFFunctiongetProgFunction (const std::string &funName)
 Get program entry function from function name. More...
 
const SVFFunctiongetProgEntryFunction ()
 Get program entry function. More...
 
bool isProgExitFunction (const SVFFunction *fun)
 Return true if this is a program exit function call. More...
 
bool isArgOfUncalledFunction (const SVFValue *svfval)
 Return true if this argument belongs to an uncalled function. More...
 
const SVFVargetForkedFun (const CallICFGNode *inst)
 Return thread fork function. More...
 
bool isExtCall (const CallICFGNode *cs)
 
bool isExtCall (const ICFGNode *node)
 
bool isHeapAllocExtCallViaArg (const CallICFGNode *cs)
 
bool isHeapAllocExtCallViaRet (const CallICFGNode *cs)
 interfaces to be used externally More...
 
bool isHeapAllocExtCall (const ICFGNode *cs)
 
u32_t getHeapAllocHoldingArgPosition (const CallICFGNode *cs)
 
bool isReallocExtCall (const CallICFGNode *cs)
 

Variables

template<typename... Ts>
constexpr bool is_sequence_container_v = is_sequence_container<Ts...>::value
 
template<typename... Ts>
constexpr bool is_map_v = is_map<Ts...>::value
 
template<typename... Ts>
constexpr bool is_set_v = is_set<Ts...>::value
 
template<typename... Ts>
using void_t = typename make_void< Ts... >::type
 
template<typename T >
constexpr bool is_iterable_v = is_iterable<T>::value
 
bool isThreadForkCall (const CallICFGNode *inst)
 
bool isThreadJoinCall (const CallICFGNode *cs)
 
bool isThreadExitCall (const CallICFGNode *cs)
 
bool isLockAquireCall (const CallICFGNode *cs)
 
bool isLockReleaseCall (const CallICFGNode *cs)
 
bool isBarrierWaitCall (const CallICFGNode *cs)
 Return true if this is a barrier wait call. More...
 
const SVFVargetActualParmAtForkSite (const CallICFGNode *cs)
 Return sole argument of the thread routine. More...
 
bool isProgExitCall (const CallICFGNode *cs)
 
template<typename T >
constexpr std::remove_reference< T >::type && move (T &&t) noexcept
 

Typedef Documentation

◆ equalNodeBS

◆ equalPointsTo

◆ PointsToList

Definition at line 166 of file SVFUtil.h.

◆ void_t

template<typename... Ts>
using SVF::SVFUtil::void_t = typedef typename make_void<Ts...>::type

Definition at line 457 of file SVFUtil.h.

Function Documentation

◆ bugMsg1()

std::string SVF::SVFUtil::bugMsg1 ( const std::string msg)

Definition at line 81 of file SVFUtil.cpp.

82 {
83  return KYEL + msg + KNRM;
84 }
#define KNRM
Color for output format.
Definition: SVFUtil.cpp:39
#define KYEL
Definition: SVFUtil.cpp:42

◆ bugMsg2()

std::string SVF::SVFUtil::bugMsg2 ( const std::string msg)

Definition at line 86 of file SVFUtil.cpp.

87 {
88  return KPUR + msg + KNRM;
89 }
#define KPUR
Definition: SVFUtil.cpp:44

◆ bugMsg3()

std::string SVF::SVFUtil::bugMsg3 ( const std::string msg)

Definition at line 91 of file SVFUtil.cpp.

92 {
93  return KCYA + msg + KNRM;
94 }
#define KCYA
Definition: SVFUtil.cpp:45

◆ cast() [1/4]

template<class X , class Y >
std::enable_if_t<!is_simple_type<Y>::value, typename cast_retty<X, const Y>::ret_type> SVF::SVFUtil::cast ( const Y &  Val)
inline

Definition at line 360 of file Casting.h.

361 {
362  assert(SVFUtil::isa<X>(Val) && "cast<Ty>() argument of incompatible type!");
363  return cast_convert_val<
364  X, const Y, typename simplify_type<const Y>::SimpleType>::doit(Val);
365 }

◆ cast() [2/4]

template<class X , class Y >
cast_retty<X, std::unique_ptr<Y> >::ret_type SVF::SVFUtil::cast ( std::unique_ptr< Y > &&  Val)
inline

Definition at line 385 of file Casting.h.

386 {
387  assert(SVFUtil::isa<X>(Val.get()) && "cast<Ty>() argument of incompatible type!");
388  using ret_type = typename cast_retty<X, std::unique_ptr<Y>>::ret_type;
389  return ret_type(
390  cast_convert_val<X, Y *, typename simplify_type<Y *>::SimpleType>::doit(
391  Val.release()));
392 }

◆ cast() [3/4]

template<class X , class Y >
cast_retty<X, Y>::ret_type SVF::SVFUtil::cast ( Y &  Val)
inline

Definition at line 368 of file Casting.h.

369 {
370  assert(SVFUtil::isa<X>(Val) && "cast<Ty>() argument of incompatible type!");
371  return cast_convert_val<X, Y,
372  typename simplify_type<Y>::SimpleType>::doit(Val);
373 }

◆ cast() [4/4]

template<class X , class Y >
cast_retty<X, Y *>::ret_type SVF::SVFUtil::cast ( Y *  Val)
inline

Definition at line 376 of file Casting.h.

377 {
378  assert(SVFUtil::isa<X>(Val) && "cast<Ty>() argument of incompatible type!");
379  return cast_convert_val<X, Y*,
380  typename simplify_type<Y*>::SimpleType>::doit(Val);
381 }

◆ cmpNodeBS()

bool SVF::SVFUtil::cmpNodeBS ( const NodeBS lpts,
const NodeBS rpts 
)
inline

Definition at line 125 of file SVFUtil.h.

126 {
127  if (lpts.count() != rpts.count())
128  return (lpts.count() < rpts.count());
129  else
130  {
131  NodeBS::iterator bit = lpts.begin(), eit = lpts.end();
132  NodeBS::iterator rbit = rpts.begin(), reit = rpts.end();
133  for (; bit != eit && rbit != reit; bit++, rbit++)
134  {
135  if (*bit != *rbit)
136  return (*bit < *rbit);
137  }
138 
139  return false;
140  }
141 }

◆ cmpPts()

bool SVF::SVFUtil::cmpPts ( const PointsTo lpts,
const PointsTo rpts 
)
inline

Compare two PointsTo according to their size and points-to elements.

  1. PointsTo with smaller size is smaller than the other;
  2. If the sizes are equal, comparing the points-to targets.

Definition at line 107 of file SVFUtil.h.

108 {
109  if (lpts.count() != rpts.count())
110  return (lpts.count() < rpts.count());
111  else
112  {
113  PointsTo::iterator bit = lpts.begin(), eit = lpts.end();
114  PointsTo::iterator rbit = rpts.begin(), reit = rpts.end();
115  for (; bit != eit && rbit != reit; bit++, rbit++)
116  {
117  if (*bit != *rbit)
118  return (*bit < *rbit);
119  }
120 
121  return false;
122  }
123 }

◆ dumpAliasSet()

void SVF::SVFUtil::dumpAliasSet ( unsigned  node,
NodeBS  bs 
)

Dump alias set.

Dump alias set

Definition at line 137 of file SVFUtil.cpp.

138 {
139  outs() << "node " << node << " alias set: {";
140  dumpSet(bs);
141  outs() << "}\n";
142 }
void dumpSet(NodeBS To, OutStream &O=SVFUtil::outs())
Dump sparse bitvector set.
Definition: SVFUtil.cpp:147
std::ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:50

◆ dumpPointsToList()

void SVF::SVFUtil::dumpPointsToList ( const PointsToList ptl)

Definition at line 122 of file SVFUtil.cpp.

123 {
124  outs() << "{";
125  for (PointsToList::const_iterator ii = ptl.begin(), ie = ptl.end();
126  ii != ie; ii++)
127  {
128  auto bs = *ii;
129  dumpSet(bs);
130  }
131  outs() << "}\n";
132 }

◆ dumpPointsToSet()

void SVF::SVFUtil::dumpPointsToSet ( unsigned  node,
NodeBS  bs 
)

Dump points-to set.

Dump points-to set

Definition at line 107 of file SVFUtil.cpp.

108 {
109  outs() << "node " << node << " points-to: {";
110  dumpSet(bs);
111  outs() << "}\n";
112 }

◆ dumpSet() [1/2]

void SVF::SVFUtil::dumpSet ( NodeBS  bs,
OutStream O = SVFUtil::outs() 
)

Dump sparse bitvector set.

Dump bit vector set

Definition at line 147 of file SVFUtil.cpp.

148 {
149  for (NodeBS::iterator ii = bs.begin(), ie = bs.end();
150  ii != ie; ii++)
151  {
152  O << " " << *ii << " ";
153  }
154 }
iterator end() const
iterator begin() const

◆ dumpSet() [2/2]

void SVF::SVFUtil::dumpSet ( PointsTo  To,
OutStream O = SVFUtil::outs() 
)

Definition at line 156 of file SVFUtil.cpp.

157 {
158  for (NodeID n : pt)
159  {
160  o << " " << n << " ";
161  }
162 }
cJSON * n
Definition: cJSON.cpp:2558
u32_t NodeID
Definition: GeneralType.h:55

◆ dumpSparseSet()

void SVF::SVFUtil::dumpSparseSet ( const NodeBS To)

Definition at line 115 of file SVFUtil.cpp.

116 {
117  outs() << "{";
118  dumpSet(bs);
119  outs() << "}\n";
120 }

◆ dyn_cast() [1/3]

template<class X , class Y >
LLVM_NODISCARD std::enable_if_t<!is_simple_type<Y>::value, typename cast_retty<X, const Y>::ret_type> SVF::SVFUtil::dyn_cast ( const Y &  Val)
inline

Definition at line 405 of file Casting.h.

406 {
407  return SVFUtil::isa<X>(Val) ? SVFUtil::cast<X>(Val) : nullptr;
408 }

◆ dyn_cast() [2/3]

template<class X , class Y >
LLVM_NODISCARD cast_retty<X, Y>::ret_type SVF::SVFUtil::dyn_cast ( Y &  Val)
inline

Definition at line 411 of file Casting.h.

412 {
413  return SVFUtil::isa<X>(Val) ? SVFUtil::cast<X>(Val) : nullptr;
414 }

◆ dyn_cast() [3/3]

template<class X , class Y >
LLVM_NODISCARD cast_retty<X, Y *>::ret_type SVF::SVFUtil::dyn_cast ( Y *  Val)
inline

Definition at line 417 of file Casting.h.

418 {
419  return SVFUtil::isa<X>(Val) ? SVFUtil::cast<X>(Val) : nullptr;
420 }

◆ errMsg()

std::string SVF::SVFUtil::errMsg ( const std::string msg)

Print error message by converting a string into red string output.

print error message by converting a string into red string output

Definition at line 76 of file SVFUtil.cpp.

77 {
78  return KRED + msg + KNRM;
79 }
#define KRED
Definition: SVFUtil.cpp:40

◆ errs()

std::ostream& SVF::SVFUtil::errs ( )
inline

Overwrite llvm::errs()

Definition at line 56 of file SVFUtil.h.

57 {
58  return std::cerr;
59 }

◆ getActualParmAtForkSite()

const SVFVar* SVF::SVFUtil::getActualParmAtForkSite ( const CallICFGNode cs)
inline

Return sole argument of the thread routine.

Definition at line 435 of file SVFUtil.h.

436 {
437  return ThreadAPI::getThreadAPI()->getActualParmAtForkSite(cs);
438 }

◆ getForkedFun()

const SVFVar* SVF::SVFUtil::getForkedFun ( const CallICFGNode inst)
inline

Return thread fork function.

Definition at line 356 of file SVFUtil.h.

357 {
358  return ThreadAPI::getThreadAPI()->getForkedFun(inst);
359 }

◆ getHeapAllocHoldingArgPosition() [1/2]

u32_t SVF::SVFUtil::getHeapAllocHoldingArgPosition ( const CallICFGNode cs)

Definition at line 357 of file SVFUtil.cpp.

358 {
360 }
const SVFFunction * getCalledFunction() const
Definition: ICFGNode.h:518
u32_t getHeapAllocHoldingArgPosition(const SVFFunction *fun)
Get the position of argument that holds an allocated heap object.
Definition: SVFUtil.h:309

◆ getHeapAllocHoldingArgPosition() [2/2]

u32_t SVF::SVFUtil::getHeapAllocHoldingArgPosition ( const SVFFunction fun)
inline

Get the position of argument that holds an allocated heap object.

Definition at line 309 of file SVFUtil.h.

310 {
311  return ExtAPI::getExtAPI()->get_alloc_arg_pos(fun);
312 }

◆ getMemoryUsageKB()

bool SVF::SVFUtil::getMemoryUsageKB ( u32_t vmrss_kb,
u32_t vmsize_kb 
)

Get memory usage from system file. Return TRUE if succeed.

Get memory usage

Definition at line 177 of file SVFUtil.cpp.

178 {
179  /* Get the current process' status file from the proc filesystem */
180  char buffer[8192];
181  FILE* procfile = fopen("/proc/self/status", "r");
182  if(procfile)
183  {
184  u32_t result = fread(buffer, sizeof(char), 8192, procfile);
185  if (result == 0)
186  {
187  fputs ("Reading error\n",stderr);
188  }
189  }
190  else
191  {
192  SVFUtil::writeWrnMsg(" /proc/self/status file not exit!");
193  return false;
194  }
195  fclose(procfile);
196 
197  /* Look through proc status contents line by line */
198  char delims[] = "\n";
199  char* line = strtok(buffer, delims);
200 
201  bool found_vmrss = false;
202  bool found_vmsize = false;
203 
204  while (line != nullptr && (found_vmrss == false || found_vmsize == false))
205  {
206  if (strstr(line, "VmRSS:") != nullptr)
207  {
208  sscanf(line, "%*s %u", vmrss_kb);
209  found_vmrss = true;
210  }
211 
212  if (strstr(line, "VmSize:") != nullptr)
213  {
214  sscanf(line, "%*s %u", vmsize_kb);
215  found_vmsize = true;
216  }
217 
218  line = strtok(nullptr, delims);
219  }
220 
221  return (found_vmrss && found_vmsize);
222 }
unsigned u32_t
Definition: CommandLine.h:18
char * buffer
Definition: cJSON.h:163
char * strstr(const char *haystack, const char *needle)
Definition: extapi.c:821
char * strtok(char *str, const char *delim)
Definition: extapi.c:463
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
Definition: SVFUtil.cpp:66

◆ getProgEntryFunction()

const SVFFunction * SVF::SVFUtil::getProgEntryFunction ( )

Get program entry function.

Get program entry function from module.

Definition at line 415 of file SVFUtil.cpp.

416 {
417  PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph();
418  for (const auto& item: *svfirCallGraph)
419  {
420  const PTACallGraphNode*fun = item.second;
421  if (isProgEntryFunction(fun->getFunction()))
422  return (fun->getFunction());
423  }
424  return nullptr;
425 }
cJSON * item
Definition: cJSON.h:222
const SVFFunction * getFunction() const
Get function of this call node.
Definition: PTACallGraph.h:198
bool isProgEntryFunction(const Function *fun)
Check whether a function is an entry function (i.e., main)
Definition: LLVMUtil.h:79

◆ getProgFunction()

const SVFFunction * SVF::SVFUtil::getProgFunction ( const std::string funName)

Get program entry function from function name.

Get program entry function from module.

Definition at line 402 of file SVFUtil.cpp.

403 {
404  PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph();
405  for (const auto& item: *svfirCallGraph)
406  {
407  const PTACallGraphNode*fun = item.second;
408  if (fun->getName()==funName)
409  return fun->getFunction();
410  }
411  return nullptr;
412 }
const std::string & getName() const
Definition: PTACallGraph.h:192

◆ hclustMethodToString()

std::string SVF::SVFUtil::hclustMethodToString ( hclust_fast_methods  method)

Returns a string representation of a hclust method.

Definition at line 260 of file SVFUtil.cpp.

261 {
262  switch (method)
263  {
265  return "single";
267  return "complete";
269  return "average";
271  return "median";
273  return "svf-best";
274  default:
275  assert(false && "SVFUtil::hclustMethodToString: unknown method");
276  abort();
277  }
278 }
@ HCLUST_METHOD_AVERAGE
Definition: fastcluster.h:72
@ HCLUST_METHOD_COMPLETE
Definition: fastcluster.h:70
@ HCLUST_METHOD_SVF_BEST
Definition: fastcluster.h:76
@ HCLUST_METHOD_MEDIAN
Definition: fastcluster.h:74
@ HCLUST_METHOD_SINGLE
Definition: fastcluster.h:68

◆ increaseStackSize()

void SVF::SVFUtil::increaseStackSize ( )

Increase the stack size limit.

Increase stack size

Definition at line 227 of file SVFUtil.cpp.

228 {
229  const rlim_t kStackSize = 256L * 1024L * 1024L; // min stack size = 256 Mb
230  struct rlimit rl;
231  int result = getrlimit(RLIMIT_STACK, &rl);
232  if (result == 0)
233  {
234  if (rl.rlim_cur < kStackSize)
235  {
236  rl.rlim_cur = kStackSize;
237  result = setrlimit(RLIMIT_STACK, &rl);
238  if (result != 0)
239  writeWrnMsg("setrlimit returned result !=0 \n");
240  }
241  }
242 }

◆ insertKey() [1/2]

template<typename Key , typename KeySet >
void SVF::SVFUtil::insertKey ( const Key &  key,
KeySet &  keySet 
)
inline

Inserts an element into a Set/CondSet (with ::insert).

Definition at line 239 of file SVFUtil.h.

240 {
241  keySet.insert(key);
242 }

◆ insertKey() [2/2]

void SVF::SVFUtil::insertKey ( const NodeID key,
NodeBS keySet 
)
inline

Inserts a NodeID into a NodeBS.

Definition at line 245 of file SVFUtil.h.

246 {
247  keySet.set(key);
248 }

◆ isa() [1/2]

template<class X , class Y >
LLVM_NODISCARD bool SVF::SVFUtil::isa ( const Y &  Val)
inline

Definition at line 241 of file Casting.h.

242 {
243  return isa_impl_wrap<X, const Y,
244  typename simplify_type<const Y>::SimpleType>::doit(Val);
245 }

◆ isa() [2/2]

template<typename First , typename Second , typename... Rest, typename Y >
LLVM_NODISCARD bool SVF::SVFUtil::isa ( const Y &  Val)
inline

Definition at line 248 of file Casting.h.

249 {
250  return SVFUtil::isa<First>(Val) || SVFUtil::isa<Second, Rest...>(Val);
251 }
LLVM_NODISCARD bool isa(const Y &Val)
Definition: Casting.h:248

◆ isArgOfUncalledFunction()

bool SVF::SVFUtil::isArgOfUncalledFunction ( const SVFValue svfval)
inline

Return true if this argument belongs to an uncalled function.

Definition at line 346 of file SVFUtil.h.

347 {
348  if(const SVFArgument* arg = SVFUtil::dyn_cast<SVFArgument>(svfval))
349  return arg->isArgOfUncalledFunction();
350  else
351  return false;
352 }

◆ isBarrierWaitCall()

bool SVF::SVFUtil::isBarrierWaitCall ( const CallICFGNode cs)
inline

Return true if this is a barrier wait call.

Definition at line 427 of file SVFUtil.h.

428 {
429  return ThreadAPI::getThreadAPI()->isTDBarWait(cs);
430 }

◆ isCallSite() [1/2]

bool SVF::SVFUtil::isCallSite ( const ICFGNode inst)

Definition at line 328 of file SVFUtil.cpp.

329 {
330  return SVFUtil::isa<CallICFGNode>(inst);
331 }

◆ isCallSite() [2/2]

bool SVF::SVFUtil::isCallSite ( const SVFValue val)
inline

Whether an instruction is a call or invoke instruction.

Definition at line 175 of file SVFUtil.h.

176 {
177  if(SVFUtil::isa<SVFCallInst>(val))
178  return true;
179  else
180  return false;
181 }

◆ isExtCall() [1/3]

bool SVF::SVFUtil::isExtCall ( const CallICFGNode cs)

Definition at line 346 of file SVFUtil.cpp.

347 {
348  return isExtCall(cs->getCalledFunction());
349 }
bool isExtCall(const SVFFunction *fun)
Definition: SVFUtil.h:278

◆ isExtCall() [2/3]

bool SVF::SVFUtil::isExtCall ( const ICFGNode node)

Definition at line 363 of file SVFUtil.cpp.

364 {
365  if(!isCallSite(node)) return false;
366  return isExtCall(cast<CallICFGNode>(node)->getCalledFunction());
367 }
bool isCallSite(const Instruction *inst)
Whether an instruction is a call or invoke instruction.
Definition: LLVMUtil.h:45

◆ isExtCall() [3/3]

bool SVF::SVFUtil::isExtCall ( const SVFFunction fun)
inline

Return true if the call is an external call (external library in function summary table) If the library function is redefined in the application code (e.g., memcpy), it will return false and will not be treated as an external call.

Definition at line 278 of file SVFUtil.h.

279 {
280  return fun && ExtAPI::getExtAPI()->is_ext(fun);
281 }

◆ isHeapAllocExtCall()

bool SVF::SVFUtil::isHeapAllocExtCall ( const ICFGNode cs)

Definition at line 369 of file SVFUtil.cpp.

370 {
371  if(!isCallSite(cs)) return false;
372  return isHeapAllocExtCallViaRet(cast<CallICFGNode>(cs)) || isHeapAllocExtCallViaArg(cast<CallICFGNode>(cs));
373 }
bool isHeapAllocExtCallViaRet(const Instruction *inst)
Definition: LLVMUtil.cpp:618
bool isHeapAllocExtCallViaArg(const Instruction *inst)
Definition: LLVMUtil.cpp:634

◆ isHeapAllocExtCallViaArg()

bool SVF::SVFUtil::isHeapAllocExtCallViaArg ( const CallICFGNode cs)

Definition at line 351 of file SVFUtil.cpp.

352 {
354 }
bool isHeapAllocExtFunViaArg(const SVFFunction *fun)
Definition: SVFUtil.h:302

◆ isHeapAllocExtCallViaRet()

bool SVF::SVFUtil::isHeapAllocExtCallViaRet ( const CallICFGNode cs)

interfaces to be used externally

Definition at line 375 of file SVFUtil.cpp.

376 {
377  bool isPtrTy = cs->getType()->isPointerTy();
378  return isPtrTy && isHeapAllocExtFunViaRet(cs->getCalledFunction());
379 }
virtual const SVFType * getType() const
Definition: GenericGraph.h:271
bool isPointerTy() const
Definition: SVFType.h:249
bool isHeapAllocExtFunViaRet(const SVFFunction *fun)
Return true if the call is a heap allocator/reallocator.
Definition: SVFUtil.h:296

◆ isHeapAllocExtFunViaArg()

bool SVF::SVFUtil::isHeapAllocExtFunViaArg ( const SVFFunction fun)
inline

Definition at line 302 of file SVFUtil.h.

303 {
304  return fun && ExtAPI::getExtAPI()->is_arg_alloc(fun);
305 }

◆ isHeapAllocExtFunViaRet()

bool SVF::SVFUtil::isHeapAllocExtFunViaRet ( const SVFFunction fun)
inline

Return true if the call is a heap allocator/reallocator.

note that these two functions are not suppose to be used externally

Definition at line 296 of file SVFUtil.h.

297 {
298  return fun && (ExtAPI::getExtAPI()->is_alloc(fun)
299  || ExtAPI::getExtAPI()->is_realloc(fun));
300 }

◆ isIntrinsicInst() [1/2]

bool SVF::SVFUtil::isIntrinsicInst ( const ICFGNode inst)

Definition at line 333 of file SVFUtil.cpp.

334 {
335  if (const CallICFGNode* call = SVFUtil::dyn_cast<CallICFGNode>(inst))
336  {
337  const SVFFunction* func = call->getCalledFunction();
338  if (func && func->isIntrinsic())
339  {
340  return true;
341  }
342  }
343  return false;
344 }
bool isIntrinsic() const
Definition: SVFValue.h:371

◆ isIntrinsicInst() [2/2]

bool SVF::SVFUtil::isIntrinsicInst ( const SVFInstruction inst)

Return true if it is an llvm intrinsic instruction.

Return true if it is an llvm intrinsic instruction

Definition at line 247 of file SVFUtil.cpp.

248 {
249  if (const SVFCallInst* call = SVFUtil::dyn_cast<SVFCallInst>(inst))
250  {
251  const SVFFunction* func = call->getCalledFunction();
252  if (func && func->isIntrinsic())
253  {
254  return true;
255  }
256  }
257  return false;
258 }

◆ isLockAquireCall()

bool SVF::SVFUtil::isLockAquireCall ( const CallICFGNode cs)
inline

Return true if this is a lock acquire call

Definition at line 411 of file SVFUtil.h.

412 {
413  return ThreadAPI::getThreadAPI()->isTDAcquire(cs);
414 }

◆ isLockReleaseCall()

bool SVF::SVFUtil::isLockReleaseCall ( const CallICFGNode cs)
inline

Return true if this is a lock acquire call

Definition at line 419 of file SVFUtil.h.

420 {
421  return ThreadAPI::getThreadAPI()->isTDRelease(cs);
422 }

◆ isMemcpyExtFun()

bool SVF::SVFUtil::isMemcpyExtFun ( const SVFFunction fun)
inline

Definition at line 283 of file SVFUtil.h.

284 {
285  return fun && ExtAPI::getExtAPI()->is_memcpy(fun);
286 }

◆ isMemsetExtFun()

bool SVF::SVFUtil::isMemsetExtFun ( const SVFFunction fun)
inline

Definition at line 288 of file SVFUtil.h.

289 {
290  return fun && ExtAPI::getExtAPI()->is_memset(fun);
291 }

◆ isNonInstricCallSite()

bool SVF::SVFUtil::isNonInstricCallSite ( const ICFGNode inst)
inline

Whether an instruction is a callsite in the application code, excluding llvm intrinsic calls.

Definition at line 189 of file SVFUtil.h.

190 {
191  if(isIntrinsicInst(inst))
192  return false;
193  return isCallSite(inst);
194 }
bool isIntrinsicInst(const ICFGNode *inst)
Definition: SVFUtil.cpp:333
bool isCallSite(const ICFGNode *inst)
Definition: SVFUtil.cpp:328

◆ isProgEntryFunction()

bool SVF::SVFUtil::isProgEntryFunction ( const SVFFunction fun)
inline

Program entry function e.g. main.

Return true if this is a program entry function (e.g. main)

Definition at line 325 of file SVFUtil.h.

326 {
327  return fun && fun->getName() == "main";
328 }

◆ isProgExitCall()

bool SVF::SVFUtil::isProgExitCall ( const CallICFGNode cs)

Definition at line 396 of file SVFUtil.cpp.

397 {
399 }
bool isProgExitFunction(const SVFFunction *fun)
Return true if this is a program exit function call.
Definition: SVFUtil.h:338

◆ isProgExitFunction()

bool SVF::SVFUtil::isProgExitFunction ( const SVFFunction fun)
inline

Return true if this is a program exit function call.

Definition at line 338 of file SVFUtil.h.

339 {
340  return fun && (fun->getName() == "exit" ||
341  fun->getName() == "__assert_rtn" ||
342  fun->getName() == "__assert_fail" );
343 }

◆ isReallocExtCall()

bool SVF::SVFUtil::isReallocExtCall ( const CallICFGNode cs)

Definition at line 381 of file SVFUtil.cpp.

382 {
383  bool isPtrTy = cs->getType()->isPointerTy();
384  return isPtrTy && isReallocExtFun(cs->getCalledFunction());
385 }
bool isReallocExtFun(const SVFFunction *fun)
Return true if the call is a heap reallocator.
Definition: SVFUtil.h:317

◆ isReallocExtFun()

bool SVF::SVFUtil::isReallocExtFun ( const SVFFunction fun)
inline

Return true if the call is a heap reallocator.

note that this function is not suppose to be used externally

Definition at line 317 of file SVFUtil.h.

318 {
319  return fun && (ExtAPI::getExtAPI()->is_realloc(fun));
320 }

◆ isRetInstNode()

bool SVF::SVFUtil::isRetInstNode ( const ICFGNode node)

Definition at line 388 of file SVFUtil.cpp.

389 {
390  if (const auto& intraNode = dyn_cast<IntraICFGNode>(node))
391  return intraNode->isRetInst();
392  else
393  return false;
394 }

◆ isThreadExitCall()

bool SVF::SVFUtil::isThreadExitCall ( const CallICFGNode cs)
inline

Return true if this is a thread exit call

Definition at line 403 of file SVFUtil.h.

404 {
405  return ThreadAPI::getThreadAPI()->isTDExit(cs);
406 }

◆ isThreadForkCall()

bool SVF::SVFUtil::isThreadForkCall ( const CallICFGNode inst)
inline

Return true if this is a thread creation call

Definition at line 387 of file SVFUtil.h.

388 {
389  return ThreadAPI::getThreadAPI()->isTDFork(inst);
390 }

◆ isThreadJoinCall()

bool SVF::SVFUtil::isThreadJoinCall ( const CallICFGNode cs)
inline

Return true if this is a thread join call

Definition at line 395 of file SVFUtil.h.

396 {
397  return ThreadAPI::getThreadAPI()->isTDJoin(cs);
398 }

◆ matchArgs()

bool SVF::SVFUtil::matchArgs ( const CallICFGNode call,
const SVFFunction callee 
)

Match arguments for callsite at caller and callee if the arg size does not match then we do not need to connect this parameter unless the callee is a variadic function (the first parameter of variadic function is its parameter number)

Match arguments for callsite at caller and callee if the arg size does not match then we do not need to connect this parameter unless the callee is a variadic function (the first parameter of variadic function is its parameter number) e.g., void variadicFoo(int num, ...); variadicFoo(5, 1,2,3,4,5) for variadic function, callsite arg size must be greater than or equal to callee arg size

Definition at line 320 of file SVFUtil.cpp.

321 {
322  if (callee->isVarArg() || ThreadAPI::getThreadAPI()->isTDFork(call))
323  return call->arg_size() >= callee->arg_size();
324  else
325  return call->arg_size() == callee->arg_size();
326 }
u32_t arg_size() const
Definition: ICFGNode.h:505
u32_t arg_size() const
Definition: SVFValue.cpp:170
bool isVarArg() const
Definition: SVFValue.cpp:181

◆ mergePtsOccMaps()

template<typename Data >
void SVF::SVFUtil::mergePtsOccMaps ( Map< Data, unsigned > &  to,
const Map< Data, unsigned >  from 
)

Given a map mapping points-to sets to a count, adds from into to.

Definition at line 226 of file SVFUtil.h.

227 {
228  for (const typename Map<Data, unsigned>::value_type &ptocc : from)
229  {
230  to[ptocc.first] += ptocc.second;
231  }
232 }

◆ move()

template<typename T >
constexpr std::remove_reference<T>::type&& SVF::SVFUtil::move ( T &&  t)
constexprnoexcept

Definition at line 447 of file SVFUtil.h.

448 {
449  return std::move(t);
450 }
constexpr std::remove_reference< T >::type && move(T &&t) noexcept
Definition: SVFUtil.h:447

◆ outs()

std::ostream& SVF::SVFUtil::outs ( )
inline

Overwrite llvm::outs()

Definition at line 50 of file SVFUtil.h.

51 {
52  return std::cout;
53 }

◆ pasMsg()

std::string SVF::SVFUtil::pasMsg ( const std::string msg)

Print each pass/phase message by converting a string into blue string output.

print each pass/phase message by converting a string into blue string output

Definition at line 99 of file SVFUtil.cpp.

100 {
101  return KBLU + msg + KNRM;
102 }
#define KBLU
Definition: SVFUtil.cpp:43

◆ ptsToNodeBS()

NodeBS SVF::SVFUtil::ptsToNodeBS ( const PointsTo pts)
inline

Definition at line 159 of file SVFUtil.h.

160 {
161  NodeBS nbs;
162  for (const NodeID o : pts) nbs.set(o);
163  return nbs;
164 }
void set(unsigned Idx)
SparseBitVector NodeBS
Definition: GeneralType.h:62

◆ removeKey() [1/2]

template<typename Key , typename KeySet >
void SVF::SVFUtil::removeKey ( const Key &  key,
KeySet &  keySet 
)
inline

Removes an element from a Set/CondSet (or anything implementing ::erase).

Definition at line 252 of file SVFUtil.h.

253 {
254  keySet.erase(key);
255 }

◆ removeKey() [2/2]

void SVF::SVFUtil::removeKey ( const NodeID key,
NodeBS keySet 
)
inline

Removes a NodeID from a NodeBS.

Definition at line 258 of file SVFUtil.h.

259 {
260  keySet.reset(key);
261 }

◆ reportMemoryUsageKB()

void SVF::SVFUtil::reportMemoryUsageKB ( const std::string infor,
OutStream O = SVFUtil::outs() 
)

Print memory usage in KB.

Print memory usage

Definition at line 167 of file SVFUtil.cpp.

168 {
169  u32_t vmrss, vmsize;
170  if (getMemoryUsageKB(&vmrss, &vmsize))
171  O << infor << "\tVmRSS: " << vmrss << "\tVmSize: " << vmsize << "\n";
172 }
bool getMemoryUsageKB(u32_t *vmrss_kb, u32_t *vmsize_kb)
Get memory usage from system file. Return TRUE if succeed.
Definition: SVFUtil.cpp:177

◆ split()

std::vector<std::string> SVF::SVFUtil::split ( const std::string s,
char  separator 
)
inline

Split into two substrings around the first occurrence of a separator string.

Definition at line 203 of file SVFUtil.h.

204 {
205  std::vector<std::string> output;
206  std::string::size_type prev_pos = 0, pos = 0;
207  while ((pos = s.find(separator, pos)) != std::string::npos)
208  {
209  std::string substring(s.substr(prev_pos, pos - prev_pos));
210  if (!substring.empty())
211  {
212  output.push_back(substring);
213  }
214  prev_pos = ++pos;
215  }
216  std::string lastSubstring(s.substr(prev_pos, pos - prev_pos));
217  if (!lastSubstring.empty())
218  {
219  output.push_back(lastSubstring);
220  }
221  return output;
222 }
const char *const string
Definition: cJSON.h:172

◆ startAnalysisLimitTimer()

bool SVF::SVFUtil::startAnalysisLimitTimer ( unsigned  timeLimit)

Starts an analysis timer. If timeLimit is 0, sets no timer. If an alarm has already been set, does not set another. Returns whether we set a timer or not.

Definition at line 289 of file SVFUtil.cpp.

290 {
291  if (timeLimit == 0) return false;
292 
293  // If an alarm is already set, don't set another. That means this analysis
294  // is part of another which has a time limit.
295  unsigned remainingSeconds = alarm(0);
296  if (remainingSeconds != 0)
297  {
298  // Continue the previous alarm and move on.
299  alarm(remainingSeconds);
300  return false;
301  }
302 
303  signal(SIGALRM, &timeLimitReached);
304  alarm(timeLimit);
305  return true;
306 }
void timeLimitReached(int signum)
Function to call when alarm for time limit hits.
Definition: SVFUtil.cpp:280

◆ stopAnalysisLimitTimer()

void SVF::SVFUtil::stopAnalysisLimitTimer ( bool  limitTimerSet)

Stops an analysis timer. limitTimerSet indicates whether the caller set the timer or not (return value of startLimitTimer).

Definition at line 310 of file SVFUtil.cpp.

311 {
312  if (limitTimerSet) alarm(0);
313 }

◆ sucMsg()

std::string SVF::SVFUtil::sucMsg ( const std::string msg)

Returns successful message by converting a string into green string output.

print successful message by converting a string into green string output

Definition at line 53 of file SVFUtil.cpp.

54 {
55  return KGRN + msg + KNRM;
56 }
#define KGRN
Definition: SVFUtil.cpp:41

◆ timeLimitReached()

void SVF::SVFUtil::timeLimitReached ( int  signum)

Function to call when alarm for time limit hits.

Definition at line 280 of file SVFUtil.cpp.

281 {
282  SVFUtil::outs().flush();
283  // TODO: output does not indicate which time limit is reached.
284  // This can be better in the future.
285  SVFUtil::outs() << "WPA: time limit reached\n";
286  exit(101);
287 }

◆ writeWrnMsg()

void SVF::SVFUtil::writeWrnMsg ( const std::string msg)

Writes a message run through wrnMsg.

Definition at line 66 of file SVFUtil.cpp.

67 {
68  if (Options::DisableWarn())
69  return;
70  outs() << wrnMsg(msg) << "\n";
71 }
std::string wrnMsg(const std::string &msg)
Returns warning message by converting a string into yellow string output.
Definition: SVFUtil.cpp:61

◆ wrnMsg()

std::string SVF::SVFUtil::wrnMsg ( const std::string msg)

Returns warning message by converting a string into yellow string output.

print warning message by converting a string into yellow string output

Definition at line 61 of file SVFUtil.cpp.

62 {
63  return KYEL + msg + KNRM;
64 }

Variable Documentation

◆ is_iterable_v

template<typename T >
constexpr bool SVF::SVFUtil::is_iterable_v = is_iterable<T>::value
constexpr

Definition at line 467 of file SVFUtil.h.

◆ is_map_v

template<typename... Ts>
constexpr bool SVF::SVFUtil::is_map_v = is_map<Ts...>::value
constexpr

Definition at line 476 of file SVFUtil.h.

◆ is_sequence_container_v

template<typename... Ts>
constexpr bool SVF::SVFUtil::is_sequence_container_v = is_sequence_container<Ts...>::value
constexpr

Definition at line 497 of file SVFUtil.h.

◆ is_set_v

template<typename... Ts>
constexpr bool SVF::SVFUtil::is_set_v = is_set<Ts...>::value
constexpr

Definition at line 485 of file SVFUtil.h.