Static Value-Flow Analysis
Loading...
Searching...
No Matches
Classes | Typedefs | Functions
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_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  simplify_type
 
struct  simplify_type< const From >
 

Typedefs

typedef struct SVF::SVFUtil::equalPointsTo equalPointsTo
 
typedef struct SVF::SVFUtil::equalNodeBS equalNodeBS
 
typedef OrderedSet< PointsTo, equalPointsTo > PointsToList
 

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 fileExists (const std::string &path)
 Check whether a file exists at the given path.
 
std::string getStdoutFromCommand (const std::string &command)
 Execute a shell command and capture its stdout output.
 
std::string getCurrentSOPath ()
 Return the absolute path of the current module/executable.
 
bool cmpPts (const PointsTo &lpts, const PointsTo &rpts)
 
bool cmpNodeBS (const NodeBS &lpts, const NodeBS &rpts)
 
void dumpPointsToList (const PointsToList &ptl)
 
bool isIntrinsicInst (const ICFGNode *inst)
 Return true if it is an llvm intrinsic 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 FunObjVar *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.
 
void startAnalysisLimitTimer (unsigned timeLimit)
 Starts analysis timer. timeLimit must be non-0. Timer must not be already set.
 
void stopAnalysisLimitTimer (void)
 Stops analysis timer.
 
bool isExtCall (const FunObjVar *fun)
 
bool isHeapAllocExtFunViaRet (const FunObjVar *fun)
 Return true if the call is a heap allocator/reallocator.
 
bool isHeapAllocExtFunViaArg (const FunObjVar *fun)
 
u32_t getHeapAllocHoldingArgPosition (const FunObjVar *fun)
 Get the position of argument that holds an allocated heap object.
 
bool isReallocExtFun (const FunObjVar *fun)
 Return true if the call is a heap reallocator.
 
bool isProgEntryFunction (const FunObjVar *)
 Program entry function e.g. main.
 
const FunObjVar * getProgFunction (const std::string &funName)
 Get program entry function from function name.
 
const FunObjVar * getProgEntryFunction ()
 Get program entry function.
 
bool isProgExitFunction (const FunObjVar *fun)
 Return true if this is a program exit function call.
 
bool isArgOfUncalledFunction (const SVFVar *svfvar)
 
const ObjVar * getObjVarOfValVar (const ValVar *valVar)
 
const ValVar * getForkedFun (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)
 
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 ValVar * getActualParmAtForkSite (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 176 of file SVFUtil.h.

Function Documentation

◆ bugMsg1()

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

Definition at line 103 of file SVFUtil.cpp.

104{
105 return KYEL + msg + KNRM;
106}
#define KNRM
Color for output format.
Definition SVFUtil.cpp:61
#define KYEL
Definition SVFUtil.cpp:64
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

◆ bugMsg2()

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

Definition at line 108 of file SVFUtil.cpp.

109{
110 return KPUR + msg + KNRM;
111}
#define KPUR
Definition SVFUtil.cpp:66

◆ bugMsg3()

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

Definition at line 113 of file SVFUtil.cpp.

114{
115 return KCYA + msg + KNRM;
116}
#define KCYA
Definition SVFUtil.cpp:67

◆ 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 142 of file SVFUtil.h.

143{
144 if (lpts.count() != rpts.count())
145 return (lpts.count() < rpts.count());
146 else
147 {
148 NodeBS::iterator bit = lpts.begin(), eit = lpts.end();
149 NodeBS::iterator rbit = rpts.begin(), reit = rpts.end();
150 for (; bit != eit && rbit != reit; bit++, rbit++)
151 {
152 if (*bit != *rbit)
153 return (*bit < *rbit);
154 }
155
156 return false;
157 }
158}

◆ 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 124 of file SVFUtil.h.

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

◆ dumpAliasSet()

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

Dump alias set.

Dump alias set

Definition at line 159 of file SVFUtil.cpp.

160{
161 outs() << "node " << node << " alias set: {";
162 dumpSet(bs);
163 outs() << "}\n";
164}
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:58
void dumpSet(NodeBS To, OutStream &O=SVFUtil::outs())
Dump sparse bitvector set.
Definition SVFUtil.cpp:169

◆ dumpPointsToList()

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

Definition at line 144 of file SVFUtil.cpp.

145{
146 outs() << "{";
147 for (PointsToList::const_iterator ii = ptl.begin(), ie = ptl.end();
148 ii != ie; ii++)
149 {
150 auto bs = *ii;
151 dumpSet(bs);
152 }
153 outs() << "}\n";
154}

◆ dumpPointsToSet()

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

Dump points-to set.

Dump points-to set

Definition at line 129 of file SVFUtil.cpp.

130{
131 outs() << "node " << node << " points-to: {";
132 dumpSet(bs);
133 outs() << "}\n";
134}

◆ dumpSet() [1/2]

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

Dump sparse bitvector set.

Dump bit vector set

Definition at line 169 of file SVFUtil.cpp.

170{
171 for (NodeBS::iterator ii = bs.begin(), ie = bs.end();
172 ii != ie; ii++)
173 {
174 O << " " << *ii << " ";
175 }
176}

◆ dumpSet() [2/2]

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

Definition at line 178 of file SVFUtil.cpp.

179{
180 for (NodeID n : pt)
181 {
182 o << " " << n << " ";
183 }
184}
cJSON * n
Definition cJSON.cpp:2558
u32_t NodeID
Definition GeneralType.h:76

◆ dumpSparseSet()

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

Definition at line 137 of file SVFUtil.cpp.

138{
139 outs() << "{";
140 dumpSet(bs);
141 outs() << "}\n";
142}

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

99{
100 return KRED + msg + KNRM;
101}
#define KRED
Definition SVFUtil.cpp:62

◆ errs()

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

Overwrite llvm::errs()

Definition at line 64 of file SVFUtil.h.

65{
66 return std::cerr;
67}

◆ fileExists()

bool SVF::SVFUtil::fileExists ( const std::string &  path)

Check whether a file exists at the given path.

Definition at line 271 of file SVFUtil.cpp.

272{
273 struct stat statbuf;
274 return !path.empty() && (stat(path.c_str(), &statbuf) == 0);
275}

◆ getActualParmAtForkSite()

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

Return sole argument of the thread routine.

Definition at line 413 of file SVFUtil.h.

414{
415 return ThreadAPI::getThreadAPI()->getActualParmAtForkSite(cs);
416}

◆ getCurrentSOPath()

std::string SVF::SVFUtil::getCurrentSOPath ( )

Return the absolute path of the current module/executable.

Definition at line 302 of file SVFUtil.cpp.

303{
304#ifdef _WIN32
305 char path[MAX_PATH];
306 HMODULE hm = NULL;
309 (LPCSTR)&getCurrentSOPath, &hm))
310 {
311 GetModuleFileNameA(hm, path, sizeof(path));
312 std::string s(path);
313 for (size_t i = 0; i < s.length(); ++i)
314 {
315 if (s[i] == '\\')
316 {
317 s[i] = '/';
318 }
319 }
320 return s;
321 }
322 return "";
323#else
325 if (dladdr((void*)&getCurrentSOPath, &info) && info.dli_fname)
326 {
327 return std::string(info.dli_fname);
328 }
329 return "";
330#endif
331}
#define NULL
Definition extapi.c:5

◆ getForkedFun()

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

Return thread fork function.

Definition at line 336 of file SVFUtil.h.

337{
338 return ThreadAPI::getThreadAPI()->getForkedFun(inst);
339}

◆ getHeapAllocHoldingArgPosition() [1/2]

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

Definition at line 434 of file SVFUtil.cpp.

435{
436 return getHeapAllocHoldingArgPosition(cs->getCalledFunction());
437}
const FunObjVar * getCalledFunction() const
Definition ICFGNode.h:501

◆ getHeapAllocHoldingArgPosition() [2/2]

u32_t SVF::SVFUtil::getHeapAllocHoldingArgPosition ( const FunObjVar *  fun)
inline

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

Definition at line 298 of file SVFUtil.h.

299{
300 return ExtAPI::getExtAPI()->get_alloc_arg_pos(fun);
301}

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

200{
201 /* Get the current process' status file from the proc filesystem */
202 char buffer[8192];
203 FILE* procfile = fopen("/proc/self/status", "r");
204 if(procfile)
205 {
206 u32_t result = fread(buffer, sizeof(char), 8192, procfile);
207 if (result == 0)
208 {
209 fputs ("Reading error\n",stderr);
210 }
211 }
212 else
213 {
214 SVFUtil::writeWrnMsg(" /proc/self/status file not exit!");
215 return false;
216 }
218
219 /* Look through proc status contents line by line */
220 char delims[] = "\n";
221 char* line = strtok(buffer, delims);
222
223 bool found_vmrss = false;
224 bool found_vmsize = false;
225
226 while (line != nullptr && (found_vmrss == false || found_vmsize == false))
227 {
228 if (strstr(line, "VmRSS:") != nullptr)
229 {
230 sscanf(line, "%*s %u", vmrss_kb);
231 found_vmrss = true;
232 }
233
234 if (strstr(line, "VmSize:") != nullptr)
235 {
236 sscanf(line, "%*s %u", vmsize_kb);
237 found_vmsize = true;
238 }
239
240 line = strtok(nullptr, delims);
241 }
242
243 return (found_vmrss && found_vmsize);
244}
char * buffer
Definition cJSON.h:163
char * strtok(char *str, const char *delim)
Definition extapi.c:498
char * strstr(const char *haystack, const char *needle)
Definition extapi.c:986
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
Definition SVFUtil.cpp:88
unsigned u32_t
Definition GeneralType.h:67

◆ getObjVarOfValVar()

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

Definition at line 520 of file SVFUtil.cpp.

521{
522 assert(valVar->getInEdges().size() == 1);
523 return SVFUtil::dyn_cast<ObjVar>((*valVar->getInEdges().begin())->getSrcNode());
524}

◆ getProgEntryFunction()

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

Get program entry function.

Get program entry function from module.

Definition at line 499 of file SVFUtil.cpp.

500{
502 for (const auto& item: *svfirCallGraph)
503 {
504 const CallGraphNode*fun = item.second;
505 if (isProgEntryFunction(fun->getFunction()))
506 return (fun->getFunction());
507 }
508 return nullptr;
509}
cJSON * item
Definition cJSON.h:222
const FunObjVar * getFunction() const
Get function of this call node.
Definition CallGraph.h:191
const CallGraph * getCallGraph()
Get CG.
Definition SVFIR.h:248
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:120

◆ getProgFunction()

const FunObjVar * SVF::SVFUtil::getProgFunction ( const std::string &  funName)

Get program entry function from function name.

Get program entry function from module.

Definition at line 486 of file SVFUtil.cpp.

487{
489 for (const auto& item: *svfirCallGraph)
490 {
491 const CallGraphNode*fun = item.second;
492 if (fun->getName()==funName)
493 return fun->getFunction();
494 }
495 return nullptr;
496}
const std::string & getName() const
Definition CallGraph.cpp:47

◆ getStdoutFromCommand()

std::string SVF::SVFUtil::getStdoutFromCommand ( const std::string &  command)

Execute a shell command and capture its stdout output.

Definition at line 277 of file SVFUtil.cpp.

278{
279 char buffer[128];
280 std::string result;
281
282 FILE* pipe = popen(command.c_str(), "r");
283 if (!pipe)
284 return "";
285
286 while (fgets(buffer, sizeof(buffer), pipe) != nullptr)
287 {
288 result += buffer;
289 }
290
291 int status = pclose(pipe);
292 if (status != 0)
293 return "";
294
295 // remove trailing newlines
296 result.erase(std::remove(result.begin(), result.end(), '\n'), result.end());
297 result.erase(std::remove(result.begin(), result.end(), '\r'), result.end());
298
299 return result;
300}
char * fgets(char *str, int n, void *stream)
Definition extapi.c:911

◆ hclustMethodToString()

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

Returns a string representation of a hclust method.

Definition at line 335 of file SVFUtil.cpp.

336{
337 switch (method)
338 {
340 return "single";
342 return "complete";
344 return "average";
346 return "median";
348 return "svf-best";
349 default:
350 assert(false && "SVFUtil::hclustMethodToString: unknown method");
351 abort();
352 }
353}
@ 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 249 of file SVFUtil.cpp.

250{
251#ifdef _WIN32
252 // On Windows, stack size is set at link time via CMake (/STACK:268435456)
253#else
254 // Increase stack size via POSIX rlimit
255 const rlim_t kStackSize = 256L * 1024L * 1024L; // min stack size = 256 Mb
256 struct rlimit rl;
258 if (result == 0)
259 {
260 if (rl.rlim_cur < kStackSize)
261 {
262 rl.rlim_cur = kStackSize;
264 if (result != 0)
265 writeWrnMsg("setrlimit returned result !=0 \n");
266 }
267 }
268#endif
269}

◆ 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 240 of file SVFUtil.h.

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

◆ insertKey() [2/2]

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

Inserts a NodeID into a NodeBS.

Definition at line 246 of file SVFUtil.h.

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

◆ 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 SVFVar *  svfvar)

Definition at line 511 of file SVFUtil.cpp.

512{
513 const ValVar* pVar = PAG::getPAG()->getBaseValVar(svfvar->getId());
514 if(const ArgValVar* arg = SVFUtil::dyn_cast<ArgValVar>(pVar))
515 return arg->isArgOfUncalledFunction();
516 else
517 return false;
518}
Class representing a function argument variable in the SVFIR.
const ValVar * getBaseValVar(NodeID id) const
Definition SVFIR.h:508

◆ isBarrierWaitCall()

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

Return true if this is a barrier wait call.

Definition at line 405 of file SVFUtil.h.

406{
407 return ThreadAPI::getThreadAPI()->isTDBarWait(cs);
408}

◆ isCallSite()

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

Definition at line 405 of file SVFUtil.cpp.

406{
407 return SVFUtil::isa<CallICFGNode>(inst);
408}

◆ isExtCall() [1/3]

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

Definition at line 423 of file SVFUtil.cpp.

424{
425 return isExtCall(cs->getCalledFunction());
426}

◆ isExtCall() [2/3]

bool SVF::SVFUtil::isExtCall ( const FunObjVar *  fun)

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

527{
528 return fun && ExtAPI::getExtAPI()->is_ext(fun);
529}
static ExtAPI * getExtAPI()
Definition ExtAPI.cpp:43
bool is_ext(const FunObjVar *funObjVar)
Definition ExtAPI.cpp:290

◆ isExtCall() [3/3]

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

Definition at line 440 of file SVFUtil.cpp.

441{
442 if(!isCallSite(node)) return false;
443 return isExtCall(cast<CallICFGNode>(node)->getCalledFunction());
444}

◆ isHeapAllocExtCall()

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

Definition at line 446 of file SVFUtil.cpp.

447{
448 if(!isCallSite(cs)) return false;
449 return isHeapAllocExtCallViaRet(cast<CallICFGNode>(cs)) || isHeapAllocExtCallViaArg(cast<CallICFGNode>(cs));
450}

◆ isHeapAllocExtCallViaArg()

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

Definition at line 428 of file SVFUtil.cpp.

429{
431}
bool isHeapAllocExtFunViaArg(const FunObjVar *fun)
Definition SVFUtil.h:290

◆ isHeapAllocExtCallViaRet()

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

interfaces to be used externally

Definition at line 452 of file SVFUtil.cpp.

453{
454 bool isPtrTy = cs->getType()->isPointerTy();
456}
bool isPointerTy() const
Definition SVFType.h:292
virtual const SVFType * getType() const
Definition SVFValue.h:169
bool isHeapAllocExtFunViaRet(const FunObjVar *fun)
Return true if the call is a heap allocator/reallocator.
Definition SVFUtil.h:284

◆ isHeapAllocExtFunViaArg()

bool SVF::SVFUtil::isHeapAllocExtFunViaArg ( const FunObjVar *  fun)
inline

Definition at line 290 of file SVFUtil.h.

291{
292 return fun && ExtAPI::getExtAPI()->is_arg_alloc(fun);
293}

◆ isHeapAllocExtFunViaRet()

bool SVF::SVFUtil::isHeapAllocExtFunViaRet ( const FunObjVar *  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 284 of file SVFUtil.h.

285{
286 return fun && (ExtAPI::getExtAPI()->is_alloc(fun)
287 || ExtAPI::getExtAPI()->is_realloc(fun));
288}

◆ isIntrinsicInst()

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

Return true if it is an llvm intrinsic instruction.

Definition at line 410 of file SVFUtil.cpp.

411{
412 if (const CallICFGNode* call = SVFUtil::dyn_cast<CallICFGNode>(inst))
413 {
414 const FunObjVar* func = call->getCalledFunction();
415 if (func && func->isIntrinsic())
416 {
417 return true;
418 }
419 }
420 return false;
421}

◆ isLockAquireCall()

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

Return true if this is a lock acquire call

Definition at line 389 of file SVFUtil.h.

390{
391 return ThreadAPI::getThreadAPI()->isTDAcquire(cs);
392}

◆ isLockReleaseCall()

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

Return true if this is a lock acquire call

Definition at line 397 of file SVFUtil.h.

398{
399 return ThreadAPI::getThreadAPI()->isTDRelease(cs);
400}

◆ 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 190 of file SVFUtil.h.

191{
192 if(isIntrinsicInst(inst))
193 return false;
194 return isCallSite(inst);
195}

◆ isProgEntryFunction()

bool SVF::SVFUtil::isProgEntryFunction ( const FunObjVar *  funObjVar)

Program entry function e.g. main.

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

Definition at line 531 of file SVFUtil.cpp.

532{
533 const char* main_name=Options::SVFMain() ? "svf.main" : "main";
534 return funObjVar && funObjVar->getName() == main_name;
535}
static Option< bool > SVFMain
Definition Options.h:173
virtual const std::string & getName() const
Definition SVFValue.h:184

◆ isProgExitCall()

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

Definition at line 480 of file SVFUtil.cpp.

481{
483}
bool isProgExitFunction(const FunObjVar *fun)
Return true if this is a program exit function call.
Definition SVFUtil.cpp:473

◆ isProgExitFunction()

bool SVF::SVFUtil::isProgExitFunction ( const FunObjVar *  fun)

Return true if this is a program exit function call.

Definition at line 473 of file SVFUtil.cpp.

474{
475 return fun && (fun->getName() == "exit" ||
476 fun->getName() == "__assert_rtn" ||
477 fun->getName() == "__assert_fail");
478}

◆ isReallocExtCall()

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

Definition at line 458 of file SVFUtil.cpp.

459{
460 bool isPtrTy = cs->getType()->isPointerTy();
462}
bool isReallocExtFun(const FunObjVar *fun)
Return true if the call is a heap reallocator.
Definition SVFUtil.h:306

◆ isReallocExtFun()

bool SVF::SVFUtil::isReallocExtFun ( const FunObjVar *  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 306 of file SVFUtil.h.

307{
308 return fun && (ExtAPI::getExtAPI()->is_realloc(fun));
309}

◆ isRetInstNode()

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

Definition at line 465 of file SVFUtil.cpp.

466{
467 if (const auto& intraNode = dyn_cast<IntraICFGNode>(node))
468 return intraNode->isRetInst();
469 else
470 return false;
471}

◆ isThreadExitCall()

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

Return true if this is a thread exit call

Definition at line 381 of file SVFUtil.h.

382{
383 return ThreadAPI::getThreadAPI()->isTDExit(cs);
384}

◆ isThreadForkCall()

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

Return true if this is a thread creation call

Definition at line 365 of file SVFUtil.h.

366{
367 return ThreadAPI::getThreadAPI()->isTDFork(inst);
368}

◆ isThreadJoinCall()

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

Return true if this is a thread join call

Definition at line 373 of file SVFUtil.h.

374{
375 return ThreadAPI::getThreadAPI()->isTDJoin(cs);
376}

◆ matchArgs()

bool SVF::SVFUtil::matchArgs ( const CallICFGNode *  call,
const FunObjVar *  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 397 of file SVFUtil.cpp.

398{
399 if (callee->isVarArg() || ThreadAPI::getThreadAPI()->isTDFork(call))
400 return call->arg_size() >= callee->arg_size();
401 else
402 return call->arg_size() == callee->arg_size();
403}
u32_t arg_size() const
Definition ICFGNode.h:488
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:99

◆ 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 227 of file SVFUtil.h.

228{
229 for (const typename Map<Data, unsigned>::value_type &ptocc : from)
230 {
231 to[ptocc.first] += ptocc.second;
232 }
233}
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition GeneralType.h:56

◆ move()

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

Definition at line 425 of file SVFUtil.h.

426{
427 return std::move(t);
428}

◆ outs()

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

Overwrite llvm::outs()

Definition at line 58 of file SVFUtil.h.

59{
60 return std::cout;
61}

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

122{
123 return KBLU + msg + KNRM;
124}
#define KBLU
Definition SVFUtil.cpp:65

◆ 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 253 of file SVFUtil.h.

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

◆ removeKey() [2/2]

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

Removes a NodeID from a NodeBS.

Definition at line 259 of file SVFUtil.h.

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

◆ reportMemoryUsageKB()

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

Print memory usage in KB.

Print memory usage

Definition at line 189 of file SVFUtil.cpp.

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

◆ 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 204 of file SVFUtil.h.

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

◆ startAnalysisLimitTimer()

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

Starts analysis timer. timeLimit must be non-0. Timer must not be already set.

Definition at line 364 of file SVFUtil.cpp.

365{
366#ifdef _WIN32
367 // POSIX alarm signals are not available on Win32
368 (void)timeLimit;
369#else
370 assert(timeLimit > 0 && "startAnalysisTimer: given non-0 time-limit.");
371
372 // If an alarm is already set, don't set another. That means this analysis
373 // is part of another which has a time limit.
374 unsigned remainingSeconds = alarm(0);
375 assert(remainingSeconds != 0 && "startAnalysisTimer: attempt to set a second alarm.");
376
377 signal(SIGALRM, &timeLimitReached);
378 alarm(timeLimit);
379#endif
380}

◆ stopAnalysisLimitTimer()

void SVF::SVFUtil::stopAnalysisLimitTimer ( void  )

Stops analysis timer.

Definition at line 383 of file SVFUtil.cpp.

384{
385#ifdef _WIN32
386 // No-op on Win32
387#else
388 alarm(0);
389#endif
390}

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

76{
77 return KGRN + msg + KNRM;
78}
#define KGRN
Definition SVFUtil.cpp:63

◆ timeLimitReached()

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

Function to call when alarm for time limit hits.

Definition at line 355 of file SVFUtil.cpp.

356{
357 SVFUtil::outs().flush();
358 // TODO: output does not indicate which time limit is reached.
359 // This can be better in the future.
360 SVFUtil::outs() << "WPA: time limit reached\n";
361 exit(101);
362}

◆ writeWrnMsg()

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

Writes a message run through wrnMsg.

Definition at line 88 of file SVFUtil.cpp.

89{
91 return;
92 outs() << wrnMsg(msg) << "\n";
93}
static const Option< bool > DisableWarn
Definition Options.h:195
std::string wrnMsg(const std::string &msg)
Returns warning message by converting a string into yellow string output.
Definition SVFUtil.cpp:83

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

84{
85 return KYEL + msg + KNRM;
86}