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 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.
 
bool startAnalysisLimitTimer (unsigned timeLimit)
 
void stopAnalysisLimitTimer (bool limitTimerSet)
 
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 FunObjVargetProgFunction (const std::string &funName)
 Get program entry function from function name.
 
const FunObjVargetProgEntryFunction ()
 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 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 168 of file SVFUtil.h.

◆ void_t

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

Definition at line 430 of file SVFUtil.h.

Function Documentation

◆ bugMsg1()

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

Definition at line 87 of file SVFUtil.cpp.

88{
89 return KYEL + msg + KNRM;
90}
#define KNRM
Color for output format.
Definition SVFUtil.cpp:45
#define KYEL
Definition SVFUtil.cpp:48
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

◆ bugMsg2()

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

Definition at line 92 of file SVFUtil.cpp.

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

◆ bugMsg3()

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

Definition at line 97 of file SVFUtil.cpp.

98{
99 return KCYA + msg + KNRM;
100}
#define KCYA
Definition SVFUtil.cpp:51

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

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

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

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

◆ dumpAliasSet()

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

Dump alias set.

Dump alias set

Definition at line 143 of file SVFUtil.cpp.

144{
145 outs() << "node " << node << " alias set: {";
146 dumpSet(bs);
147 outs() << "}\n";
148}
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52
void dumpSet(NodeBS To, OutStream &O=SVFUtil::outs())
Dump sparse bitvector set.
Definition SVFUtil.cpp:153

◆ dumpPointsToList()

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

Definition at line 128 of file SVFUtil.cpp.

129{
130 outs() << "{";
131 for (PointsToList::const_iterator ii = ptl.begin(), ie = ptl.end();
132 ii != ie; ii++)
133 {
134 auto bs = *ii;
135 dumpSet(bs);
136 }
137 outs() << "}\n";
138}

◆ dumpPointsToSet()

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

Dump points-to set.

Dump points-to set

Definition at line 113 of file SVFUtil.cpp.

114{
115 outs() << "node " << node << " points-to: {";
116 dumpSet(bs);
117 outs() << "}\n";
118}

◆ dumpSet() [1/2]

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

Dump sparse bitvector set.

Dump bit vector set

Definition at line 153 of file SVFUtil.cpp.

154{
155 for (NodeBS::iterator ii = bs.begin(), ie = bs.end();
156 ii != ie; ii++)
157 {
158 O << " " << *ii << " ";
159 }
160}

◆ dumpSet() [2/2]

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

Definition at line 162 of file SVFUtil.cpp.

163{
164 for (NodeID n : pt)
165 {
166 o << " " << n << " ";
167 }
168}
cJSON * n
Definition cJSON.cpp:2558
u32_t NodeID
Definition GeneralType.h:76

◆ dumpSparseSet()

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

Definition at line 121 of file SVFUtil.cpp.

122{
123 outs() << "{";
124 dumpSet(bs);
125 outs() << "}\n";
126}

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

83{
84 return KRED + msg + KNRM;
85}
#define KRED
Definition SVFUtil.cpp:46

◆ errs()

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

Overwrite llvm::errs()

Definition at line 58 of file SVFUtil.h.

59{
60 return std::cerr;
61}

◆ getActualParmAtForkSite()

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

Return sole argument of the thread routine.

Definition at line 408 of file SVFUtil.h.

409{
410 return ThreadAPI::getThreadAPI()->getActualParmAtForkSite(cs);
411}

◆ getForkedFun()

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

Return thread fork function.

Definition at line 331 of file SVFUtil.h.

332{
333 return ThreadAPI::getThreadAPI()->getForkedFun(inst);
334}

◆ getHeapAllocHoldingArgPosition() [1/2]

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

Definition at line 349 of file SVFUtil.cpp.

350{
351 return getHeapAllocHoldingArgPosition(cs->getCalledFunction());
352}
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 293 of file SVFUtil.h.

294{
295 return ExtAPI::getExtAPI()->get_alloc_arg_pos(fun);
296}

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

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

◆ getObjVarOfValVar()

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

Definition at line 435 of file SVFUtil.cpp.

436{
437 assert(valVar->getInEdges().size() == 1);
438 return SVFUtil::dyn_cast<ObjVar>((*valVar->getInEdges().begin())->getSrcNode());
439}

◆ getProgEntryFunction()

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

Get program entry function.

Get program entry function from module.

Definition at line 414 of file SVFUtil.cpp.

415{
417 for (const auto& item: *svfirCallGraph)
418 {
419 const CallGraphNode*fun = item.second;
420 if (isProgEntryFunction(fun->getFunction()))
421 return (fun->getFunction());
422 }
423 return nullptr;
424}
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 401 of file SVFUtil.cpp.

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

◆ hclustMethodToString()

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

Returns a string representation of a hclust method.

Definition at line 252 of file SVFUtil.cpp.

253{
254 switch (method)
255 {
257 return "single";
259 return "complete";
261 return "average";
263 return "median";
265 return "svf-best";
266 default:
267 assert(false && "SVFUtil::hclustMethodToString: unknown method");
268 abort();
269 }
270}
@ 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 233 of file SVFUtil.cpp.

234{
235 const rlim_t kStackSize = 256L * 1024L * 1024L; // min stack size = 256 Mb
236 struct rlimit rl;
238 if (result == 0)
239 {
240 if (rl.rlim_cur < kStackSize)
241 {
242 rl.rlim_cur = kStackSize;
244 if (result != 0)
245 writeWrnMsg("setrlimit returned result !=0 \n");
246 }
247 }
248}

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

233{
234 keySet.insert(key);
235}

◆ insertKey() [2/2]

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

Inserts a NodeID into a NodeBS.

Definition at line 238 of file SVFUtil.h.

239{
240 keySet.set(key);
241}

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

427{
428 const ValVar* pVar = PAG::getPAG()->getBaseValVar(svfvar->getId());
429 if(const ArgValVar* arg = SVFUtil::dyn_cast<ArgValVar>(pVar))
430 return arg->isArgOfUncalledFunction();
431 else
432 return false;
433}
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 400 of file SVFUtil.h.

401{
402 return ThreadAPI::getThreadAPI()->isTDBarWait(cs);
403}

◆ isCallSite()

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

Definition at line 320 of file SVFUtil.cpp.

321{
322 return SVFUtil::isa<CallICFGNode>(inst);
323}

◆ isExtCall() [1/3]

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

Definition at line 338 of file SVFUtil.cpp.

339{
340 return isExtCall(cs->getCalledFunction());
341}

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

442{
443 return fun && ExtAPI::getExtAPI()->is_ext(fun);
444}
static ExtAPI * getExtAPI()
Definition ExtAPI.cpp:44
bool is_ext(const FunObjVar *funObjVar)
Definition ExtAPI.cpp:333

◆ isExtCall() [3/3]

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

Definition at line 355 of file SVFUtil.cpp.

356{
357 if(!isCallSite(node)) return false;
358 return isExtCall(cast<CallICFGNode>(node)->getCalledFunction());
359}

◆ isHeapAllocExtCall()

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

Definition at line 361 of file SVFUtil.cpp.

362{
363 if(!isCallSite(cs)) return false;
364 return isHeapAllocExtCallViaRet(cast<CallICFGNode>(cs)) || isHeapAllocExtCallViaArg(cast<CallICFGNode>(cs));
365}

◆ isHeapAllocExtCallViaArg()

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

Definition at line 343 of file SVFUtil.cpp.

344{
346}
bool isHeapAllocExtFunViaArg(const FunObjVar *fun)
Definition SVFUtil.h:285

◆ isHeapAllocExtCallViaRet()

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

interfaces to be used externally

Definition at line 367 of file SVFUtil.cpp.

368{
369 bool isPtrTy = cs->getType()->isPointerTy();
371}
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:279

◆ isHeapAllocExtFunViaArg()

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

Definition at line 285 of file SVFUtil.h.

286{
287 return fun && ExtAPI::getExtAPI()->is_arg_alloc(fun);
288}

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

280{
281 return fun && (ExtAPI::getExtAPI()->is_alloc(fun)
282 || ExtAPI::getExtAPI()->is_realloc(fun));
283}

◆ isIntrinsicInst()

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

Return true if it is an llvm intrinsic instruction.

Definition at line 325 of file SVFUtil.cpp.

326{
327 if (const CallICFGNode* call = SVFUtil::dyn_cast<CallICFGNode>(inst))
328 {
329 const FunObjVar* func = call->getCalledFunction();
330 if (func && func->isIntrinsic())
331 {
332 return true;
333 }
334 }
335 return false;
336}

◆ isLockAquireCall()

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

Return true if this is a lock acquire call

Definition at line 384 of file SVFUtil.h.

385{
386 return ThreadAPI::getThreadAPI()->isTDAcquire(cs);
387}

◆ isLockReleaseCall()

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

Return true if this is a lock acquire call

Definition at line 392 of file SVFUtil.h.

393{
394 return ThreadAPI::getThreadAPI()->isTDRelease(cs);
395}

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

183{
184 if(isIntrinsicInst(inst))
185 return false;
186 return isCallSite(inst);
187}

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

447{
448 const char* main_name=Options::SVFMain() ? "svf.main" : "main";
449 return funObjVar && funObjVar->getName() == main_name;
450}
static Option< bool > SVFMain
Definition Options.h:176
virtual const std::string & getName() const
Definition SVFValue.h:184

◆ isProgExitCall()

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

Definition at line 395 of file SVFUtil.cpp.

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

◆ isProgExitFunction()

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

Return true if this is a program exit function call.

Definition at line 388 of file SVFUtil.cpp.

389{
390 return fun && (fun->getName() == "exit" ||
391 fun->getName() == "__assert_rtn" ||
392 fun->getName() == "__assert_fail");
393}

◆ isReallocExtCall()

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

Definition at line 373 of file SVFUtil.cpp.

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

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

302{
303 return fun && (ExtAPI::getExtAPI()->is_realloc(fun));
304}

◆ isRetInstNode()

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

Definition at line 380 of file SVFUtil.cpp.

381{
382 if (const auto& intraNode = dyn_cast<IntraICFGNode>(node))
383 return intraNode->isRetInst();
384 else
385 return false;
386}

◆ isThreadExitCall()

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

Return true if this is a thread exit call

Definition at line 376 of file SVFUtil.h.

377{
378 return ThreadAPI::getThreadAPI()->isTDExit(cs);
379}

◆ isThreadForkCall()

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

Return true if this is a thread creation call

Definition at line 360 of file SVFUtil.h.

361{
362 return ThreadAPI::getThreadAPI()->isTDFork(inst);
363}

◆ isThreadJoinCall()

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

Return true if this is a thread join call

Definition at line 368 of file SVFUtil.h.

369{
370 return ThreadAPI::getThreadAPI()->isTDJoin(cs);
371}

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

313{
314 if (callee->isVarArg() || ThreadAPI::getThreadAPI()->isTDFork(call))
315 return call->arg_size() >= callee->arg_size();
316 else
317 return call->arg_size() == callee->arg_size();
318}
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:98

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

220{
221 for (const typename Map<Data, unsigned>::value_type &ptocc : from)
222 {
223 to[ptocc.first] += ptocc.second;
224 }
225}
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 420 of file SVFUtil.h.

421{
422 return std::move(t);
423}

◆ outs()

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

Overwrite llvm::outs()

Definition at line 52 of file SVFUtil.h.

53{
54 return std::cout;
55}

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

106{
107 return KBLU + msg + KNRM;
108}
#define KBLU
Definition SVFUtil.cpp:49

◆ ptsToNodeBS()

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

Definition at line 161 of file SVFUtil.h.

162{
163 NodeBS nbs;
164 for (const NodeID o : pts) nbs.set(o);
165 return nbs;
166}

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

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

◆ removeKey() [2/2]

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

Removes a NodeID from a NodeBS.

Definition at line 251 of file SVFUtil.h.

252{
253 keySet.reset(key);
254}

◆ reportMemoryUsageKB()

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

Print memory usage in KB.

Print memory usage

Definition at line 173 of file SVFUtil.cpp.

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

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

197{
198 std::vector<std::string> output;
199 std::string::size_type prev_pos = 0, pos = 0;
200 while ((pos = s.find(separator, pos)) != std::string::npos)
201 {
202 std::string substring(s.substr(prev_pos, pos - prev_pos));
203 if (!substring.empty())
204 {
205 output.push_back(substring);
206 }
207 prev_pos = ++pos;
208 }
209 std::string lastSubstring(s.substr(prev_pos, pos - prev_pos));
210 if (!lastSubstring.empty())
211 {
212 output.push_back(lastSubstring);
213 }
214 return output;
215}

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

282{
283 if (timeLimit == 0) return false;
284
285 // If an alarm is already set, don't set another. That means this analysis
286 // is part of another which has a time limit.
287 unsigned remainingSeconds = alarm(0);
288 if (remainingSeconds != 0)
289 {
290 // Continue the previous alarm and move on.
292 return false;
293 }
294
295 signal(SIGALRM, &timeLimitReached);
297 return true;
298}

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

303{
304 if (limitTimerSet) alarm(0);
305}

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

60{
61 return KGRN + msg + KNRM;
62}
#define KGRN
Definition SVFUtil.cpp:47

◆ timeLimitReached()

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

Function to call when alarm for time limit hits.

Definition at line 272 of file SVFUtil.cpp.

273{
274 SVFUtil::outs().flush();
275 // TODO: output does not indicate which time limit is reached.
276 // This can be better in the future.
277 SVFUtil::outs() << "WPA: time limit reached\n";
278 exit(101);
279}

◆ writeWrnMsg()

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

Writes a message run through wrnMsg.

Definition at line 72 of file SVFUtil.cpp.

73{
75 return;
76 outs() << wrnMsg(msg) << "\n";
77}
static const Option< bool > DisableWarn
Definition Options.h:198
std::string wrnMsg(const std::string &msg)
Returns warning message by converting a string into yellow string output.
Definition SVFUtil.cpp:67

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

68{
69 return KYEL + msg + KNRM;
70}

Variable Documentation

◆ is_iterable_v

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

Definition at line 440 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 449 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 470 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 458 of file SVFUtil.h.