Static Value-Flow Analysis
Loading...
Searching...
No Matches
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  cast_convert_val
 
struct  cast_convert_val< To, FromTy, FromTy >
 
struct  cast_retty
 
struct  cast_retty_impl
 
struct  cast_retty_impl< To, const From * >
 
struct  cast_retty_impl< To, const From *const >
 
struct  cast_retty_impl< To, const From >
 
struct  cast_retty_impl< To, From * >
 
struct  cast_retty_impl< To, std::unique_ptr< From > >
 
struct  cast_retty_wrap
 
struct  cast_retty_wrap< To, FromTy, FromTy >
 
struct  equalNodeBS
 
struct  equalPointsTo
 
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_sequence_container
 Type trait to check if a type is vector or list. More...
 
struct  is_sequence_container< std::deque< Ts... > >
 
struct  is_sequence_container< std::list< Ts... > >
 
struct  is_sequence_container< std::vector< 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_simple_type
 
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 From *const >
 
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_wrap
 
struct  isa_impl_wrap< To, FromTy, FromTy >
 
struct  make_void
 void_t is not available until C++17. We define it here for C++11/14. More...
 
struct  simplify_type
 
struct  simplify_type< const From >
 

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()
 
std::ostream & errs ()
 Overwrite llvm::errs()
 
void dumpSet (NodeBS To, OutStream &O=SVFUtil::outs())
 Dump sparse bitvector set.
 
void dumpSet (PointsTo To, OutStream &O=SVFUtil::outs())
 
void dumpPointsToSet (unsigned node, NodeBS To)
 Dump points-to set.
 
void dumpSparseSet (const NodeBS &To)
 
void dumpAliasSet (unsigned node, NodeBS To)
 Dump alias set.
 
std::string sucMsg (const std::string &msg)
 Returns successful message by converting a string into green string output.
 
std::string wrnMsg (const std::string &msg)
 Returns warning message by converting a string into yellow string output.
 
void writeWrnMsg (const std::string &msg)
 Writes a message run through wrnMsg.
 
std::string errMsg (const std::string &msg)
 Print error message by converting a string into red string output.
 
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.
 
void reportMemoryUsageKB (const std::string &infor, OutStream &O=SVFUtil::outs())
 Print memory usage in KB.
 
bool getMemoryUsageKB (u32_t *vmrss_kb, u32_t *vmsize_kb)
 Get memory usage from system file. Return TRUE if succeed.
 
void increaseStackSize ()
 Increase the stack size limit.
 
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.
 
bool isIntrinsicInst (const ICFGNode *inst)
 
bool isCallSite (const SVFValue *val)
 Whether an instruction is a call or invoke instruction.
 
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.
 
bool matchArgs (const CallICFGNode *cs, const SVFFunction *callee)
 
std::vector< std::string > split (const std::string &s, char separator)
 Split into two substrings around the first occurrence of a separator string.
 
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.
 
std::string hclustMethodToString (hclust_fast_methods method)
 Returns a string representation of a hclust method.
 
template<typename Key , typename KeySet >
void insertKey (const Key &key, KeySet &keySet)
 Inserts an element into a Set/CondSet (with ::insert).
 
void insertKey (const NodeID &key, NodeBS &keySet)
 Inserts a NodeID into a NodeBS.
 
template<typename Key , typename KeySet >
void removeKey (const Key &key, KeySet &keySet)
 Removes an element from a Set/CondSet (or anything implementing erase).
 
void removeKey (const NodeID &key, NodeBS &keySet)
 Removes a NodeID from a NodeBS.
 
void timeLimitReached (int signum)
 Function to call when alarm for time limit hits.
 
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.
 
bool isHeapAllocExtFunViaArg (const SVFFunction *fun)
 
u32_t getHeapAllocHoldingArgPosition (const SVFFunction *fun)
 Get the position of argument that holds an allocated heap object.
 
bool isReallocExtFun (const SVFFunction *fun)
 Return true if the call is a heap reallocator.
 
bool isProgEntryFunction (const SVFFunction *fun)
 Program entry function e.g. main.
 
const SVFFunctiongetProgFunction (const std::string &funName)
 Get program entry function from function name.
 
const SVFFunctiongetProgEntryFunction ()
 Get program entry function.
 
bool isProgExitFunction (const SVFFunction *fun)
 Return true if this is a program exit function call.
 
bool isArgOfUncalledFunction (const SVFValue *svfval)
 Return true if this argument belongs to an uncalled function.
 
const ObjVargetObjVarOfValVar (const ValVar *valVar)
 
const ValVargetForkedFun (const CallICFGNode *inst)
 Return thread fork function.
 
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
 
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.
 
const ValVargetActualParmAtForkSite (const CallICFGNode *cs)
 Return sole argument of the thread routine.
 
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 82 of file SVFUtil.cpp.

83{
84 return KYEL + msg + KNRM;
85}
#define KNRM
Color for output format.
Definition SVFUtil.cpp:40
#define KYEL
Definition SVFUtil.cpp:43
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74

◆ bugMsg2()

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

Definition at line 87 of file SVFUtil.cpp.

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

◆ bugMsg3()

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

Definition at line 92 of file SVFUtil.cpp.

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

◆ 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(
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 138 of file SVFUtil.cpp.

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

◆ dumpPointsToList()

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

Definition at line 123 of file SVFUtil.cpp.

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

◆ dumpPointsToSet()

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

Dump points-to set.

Dump points-to set

Definition at line 108 of file SVFUtil.cpp.

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

◆ dumpSet() [1/2]

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

Dump sparse bitvector set.

Dump bit vector set

Definition at line 148 of file SVFUtil.cpp.

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

◆ dumpSet() [2/2]

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

Definition at line 157 of file SVFUtil.cpp.

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

◆ dumpSparseSet()

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

Definition at line 116 of file SVFUtil.cpp.

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

◆ 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 77 of file SVFUtil.cpp.

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

◆ 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 ValVar * 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 ValVar * SVF::SVFUtil::getForkedFun ( const CallICFGNode inst)
inline

Return thread fork function.

Definition at line 358 of file SVFUtil.h.

359{
360 return ThreadAPI::getThreadAPI()->getForkedFun(inst);
361}

◆ getHeapAllocHoldingArgPosition() [1/2]

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

Definition at line 358 of file SVFUtil.cpp.

359{
361}
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 178 of file SVFUtil.cpp.

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

◆ getObjVarOfValVar()

const ObjVar * SVF::SVFUtil::getObjVarOfValVar ( const ValVar valVar)

Definition at line 429 of file SVFUtil.cpp.

430{
431 assert(valVar->getInEdges().size() == 1);
432 return SVFUtil::dyn_cast<ObjVar>((*valVar->getInEdges().begin())->getSrcNode());
433}

◆ getProgEntryFunction()

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

Get program entry function.

Get program entry function from module.

Definition at line 416 of file SVFUtil.cpp.

417{
419 for (const auto& item: *svfirCallGraph)
420 {
421 const CallGraphNode*fun = item.second;
422 if (isProgEntryFunction(fun->getFunction()))
423 return (fun->getFunction());
424 }
425 return nullptr;
426}
cJSON * item
Definition cJSON.h:222
const SVFFunction * getFunction() const
Get function of this call node.
Definition CallGraph.h:131
CallGraph * getCallGraph()
Definition SVFIR.h:193
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:116

◆ 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 403 of file SVFUtil.cpp.

404{
406 for (const auto& item: *svfirCallGraph)
407 {
408 const CallGraphNode*fun = item.second;
409 if (fun->getName()==funName)
410 return fun->getFunction();
411 }
412 return nullptr;
413}
const std::string & getName() const
Definition CallGraph.h:125

◆ hclustMethodToString()

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

Returns a string representation of a hclust method.

Definition at line 261 of file SVFUtil.cpp.

262{
263 switch (method)
264 {
266 return "single";
268 return "complete";
270 return "average";
272 return "median";
274 return "svf-best";
275 default:
276 assert(false && "SVFUtil::hclustMethodToString: unknown method");
277 abort();
278 }
279}
@ 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 228 of file SVFUtil.cpp.

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

◆ 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,
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}

◆ 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 329 of file SVFUtil.cpp.

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

◆ 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 347 of file SVFUtil.cpp.

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

◆ isExtCall() [2/3]

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

Definition at line 364 of file SVFUtil.cpp.

365{
366 if(!isCallSite(node)) return false;
367 return isExtCall(cast<CallICFGNode>(node)->getCalledFunction());
368}

◆ 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 370 of file SVFUtil.cpp.

371{
372 if(!isCallSite(cs)) return false;
373 return isHeapAllocExtCallViaRet(cast<CallICFGNode>(cs)) || isHeapAllocExtCallViaArg(cast<CallICFGNode>(cs));
374}

◆ isHeapAllocExtCallViaArg()

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

Definition at line 352 of file SVFUtil.cpp.

353{
355}
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 376 of file SVFUtil.cpp.

377{
378 bool isPtrTy = cs->getType()->isPointerTy();
380}
virtual const SVFType * getType() const
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 334 of file SVFUtil.cpp.

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

◆ 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 248 of file SVFUtil.cpp.

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

◆ 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}

◆ 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}
const std::string & getName() const
Definition SVFValue.h:243

◆ isProgExitCall()

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

Definition at line 397 of file SVFUtil.cpp.

398{
400}
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 382 of file SVFUtil.cpp.

383{
384 bool isPtrTy = cs->getType()->isPointerTy();
386}
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 389 of file SVFUtil.cpp.

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

◆ 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 321 of file SVFUtil.cpp.

322{
323 if (callee->isVarArg() || ThreadAPI::getThreadAPI()->isTDFork(call))
324 return call->arg_size() >= callee->arg_size();
325 else
326 return call->arg_size() == callee->arg_size();
327}
u32_t arg_size() const
Definition ICFGNode.h:505
bool isTDFork(const CallICFGNode *inst) const
Return true if this call create a new thread.
static ThreadAPI * getThreadAPI()
Return a static reference.
Definition ThreadAPI.h:107

◆ 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}
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map

◆ 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}

◆ 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 100 of file SVFUtil.cpp.

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

◆ 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}
set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) add_llvm_executable(wpa wpa.cpp) target_link_libraries(wpa PUBLIC $
Definition CMakeLists.txt:1

◆ 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 168 of file SVFUtil.cpp.

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

◆ 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}

◆ 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 290 of file SVFUtil.cpp.

291{
292 if (timeLimit == 0) return false;
293
294 // If an alarm is already set, don't set another. That means this analysis
295 // is part of another which has a time limit.
296 unsigned remainingSeconds = alarm(0);
297 if (remainingSeconds != 0)
298 {
299 // Continue the previous alarm and move on.
301 return false;
302 }
303
304 signal(SIGALRM, &timeLimitReached);
306 return true;
307}

◆ 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 311 of file SVFUtil.cpp.

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

◆ 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 54 of file SVFUtil.cpp.

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

◆ timeLimitReached()

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

Function to call when alarm for time limit hits.

Definition at line 281 of file SVFUtil.cpp.

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

◆ writeWrnMsg()

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

Writes a message run through wrnMsg.

Definition at line 67 of file SVFUtil.cpp.

68{
70 return;
71 outs() << wrnMsg(msg) << "\n";
72}
static const Option< bool > DisableWarn
Definition Options.h:205
std::string wrnMsg(const std::string &msg)
Returns warning message by converting a string into yellow string output.
Definition SVFUtil.cpp:62

◆ 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 62 of file SVFUtil.cpp.

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

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.