30 #ifndef AnalysisUtil_H_
31 #define AnalysisUtil_H_
50 inline std::ostream &
outs()
56 inline std::ostream &
errs()
115 for (; bit != eit && rbit != reit; bit++, rbit++)
118 return (*bit < *rbit);
133 for (; bit != eit && rbit != reit; bit++, rbit++)
136 return (*bit < *rbit);
177 if(SVFUtil::isa<SVFCallInst>(val))
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)
209 std::string substring(s.substr(prev_pos, pos - prev_pos));
210 if (!substring.empty())
212 output.push_back(substring);
216 std::string lastSubstring(s.substr(prev_pos, pos - prev_pos));
217 if (!lastSubstring.empty())
219 output.push_back(lastSubstring);
225 template <
typename Data>
230 to[ptocc.first] += ptocc.second;
238 template <
typename Key,
typename KeySet>
251 template <
typename Key,
typename KeySet>
327 return fun && fun->getName() ==
"main";
340 return fun && (fun->
getName() ==
"exit" ||
341 fun->
getName() ==
"__assert_rtn" ||
342 fun->
getName() ==
"__assert_fail" );
348 if(
const SVFArgument* arg = SVFUtil::dyn_cast<SVFArgument>(svfval))
349 return arg->isArgOfUncalledFunction();
462 template <
typename T,
typename =
void>
struct is_iterable : std::false_type {};
463 template <
typename T>
465 std::end(std::declval<T&>()))>>
472 template <
typename T>
struct is_map : std::false_type {};
473 template <
typename... Ts>
struct is_map<std::map<Ts...>> : std::true_type {};
474 template <
typename... Ts>
475 struct is_map<std::unordered_map<Ts...>> : std::true_type {};
481 template <
typename T>
struct is_set : std::false_type {};
482 template <
typename... Ts>
struct is_set<std::
set<Ts...>> : std::true_type {};
483 template <
typename... Ts>
484 struct is_set<std::unordered_set<Ts...>> : std::true_type {};
490 template <
typename... Ts>
492 template <
typename... Ts>
494 template <
typename... Ts>
496 template <
typename... Ts>
set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) add_llvm_executable(wpa wpa.cpp) target_link_libraries(wpa PUBLIC $
bool is_alloc(const SVFFunction *F)
bool is_arg_alloc(const SVFFunction *F)
bool is_ext(const SVFFunction *F)
static ExtAPI * getExtAPI()
s32_t get_alloc_arg_pos(const SVFFunction *F)
bool is_memset(const SVFFunction *F)
bool is_memcpy(const SVFFunction *F)
bool is_realloc(const SVFFunction *F)
const_iterator end() const
u32_t count() const
Returns number of elements.
const_iterator begin() const
const std::string & getName() const
bool isTDFork(const CallICFGNode *inst) const
Return true if this call create a new thread.
bool isTDJoin(const CallICFGNode *inst) const
Return true if this call wait for a worker thread.
bool isTDRelease(const CallICFGNode *inst) const
Return true if this call release a lock.
static ThreadAPI * getThreadAPI()
Return a static reference.
const SVFVar * getForkedFun(const CallICFGNode *inst) const
bool isTDExit(const CallICFGNode *inst) const
Return true if this call exits/terminate a thread.
const SVFVar * getActualParmAtForkSite(const CallICFGNode *inst) const
bool isTDBarWait(const CallICFGNode *inst) const
Return true if this call waits for a barrier.
bool isTDAcquire(const CallICFGNode *inst) const
Return true if this call acquire a lock.
bool isReallocExtCall(const CallICFGNode *cs)
std::string sucMsg(const std::string &msg)
Returns successful message by converting a string into green string output.
void increaseStackSize()
Increase the stack size limit.
std::string bugMsg1(const std::string &msg)
std::string hclustMethodToString(hclust_fast_methods method)
Returns a string representation of a hclust method.
void stopAnalysisLimitTimer(bool limitTimerSet)
bool isLockAquireCall(const CallICFGNode *cs)
bool isHeapAllocExtFunViaRet(const SVFFunction *fun)
Return true if the call is a heap allocator/reallocator.
bool isArgOfUncalledFunction(const SVFValue *svfval)
Return true if this argument belongs to an uncalled function.
bool isExtCall(const SVFFunction *fun)
bool isProgEntryFunction(const SVFFunction *fun)
Program entry function e.g. main.
bool isBarrierWaitCall(const CallICFGNode *cs)
Return true if this is a barrier wait call.
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 pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
OrderedSet< PointsTo, equalPointsTo > PointsToList
void dumpAliasSet(unsigned node, NodeBS To)
Dump alias set.
const SVFVar * getActualParmAtForkSite(const CallICFGNode *cs)
Return sole argument of the thread routine.
bool isMemsetExtFun(const SVFFunction *fun)
bool getMemoryUsageKB(u32_t *vmrss_kb, u32_t *vmsize_kb)
Get memory usage from system file. Return TRUE if succeed.
bool isMemcpyExtFun(const SVFFunction *fun)
void reportMemoryUsageKB(const std::string &infor, OutStream &O=SVFUtil::outs())
Print memory usage in KB.
constexpr std::remove_reference< T >::type && move(T &&t) noexcept
bool startAnalysisLimitTimer(unsigned timeLimit)
std::string errMsg(const std::string &msg)
Print error message by converting a string into red string output.
std::string bugMsg3(const std::string &msg)
constexpr bool is_sequence_container_v
bool isHeapAllocExtCallViaArg(const CallICFGNode *cs)
bool isHeapAllocExtCall(const ICFGNode *cs)
u32_t getHeapAllocHoldingArgPosition(const SVFFunction *fun)
Get the position of argument that holds an allocated heap object.
bool isNonInstricCallSite(const ICFGNode *inst)
Whether an instruction is a callsite in the application code, excluding llvm intrinsic calls.
bool isThreadJoinCall(const CallICFGNode *cs)
NodeBS ptsToNodeBS(const PointsTo &pts)
bool isCallSite(const SVFValue *val)
Whether an instruction is a call or invoke instruction.
bool cmpNodeBS(const NodeBS &lpts, const NodeBS &rpts)
bool isReallocExtFun(const SVFFunction *fun)
Return true if the call is a heap reallocator.
constexpr bool is_iterable_v
bool cmpPts(const PointsTo &lpts, const PointsTo &rpts)
const SVFVar * getForkedFun(const CallICFGNode *inst)
Return thread fork function.
bool isThreadForkCall(const CallICFGNode *inst)
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
void dumpSparseSet(const NodeBS &To)
bool isHeapAllocExtFunViaArg(const SVFFunction *fun)
std::ostream & errs()
Overwrite llvm::errs()
bool isLockReleaseCall(const CallICFGNode *cs)
bool isIntrinsicInst(const SVFInstruction *inst)
Return true if it is an llvm intrinsic instruction.
void dumpPointsToSet(unsigned node, NodeBS To)
Dump points-to set.
struct SVF::SVFUtil::equalPointsTo equalPointsTo
bool isThreadExitCall(const CallICFGNode *cs)
std::string bugMsg2(const std::string &msg)
bool isProgExitCall(const CallICFGNode *cs)
std::string wrnMsg(const std::string &msg)
Returns warning message by converting a string into yellow string output.
struct SVF::SVFUtil::equalNodeBS equalNodeBS
typename make_void< Ts... >::type void_t
bool isRetInstNode(const ICFGNode *node)
bool matchArgs(const CallICFGNode *cs, const SVFFunction *callee)
void timeLimitReached(int signum)
Function to call when alarm for time limit hits.
const SVFFunction * getProgFunction(const std::string &funName)
Get program entry function from function name.
std::vector< std::string > split(const std::string &s, char separator)
Split into two substrings around the first occurrence of a separator string.
bool isHeapAllocExtCallViaRet(const CallICFGNode *cs)
interfaces to be used externally
void dumpSet(NodeBS To, OutStream &O=SVFUtil::outs())
Dump sparse bitvector set.
bool isProgExitFunction(const SVFFunction *fun)
Return true if this is a program exit function call.
std::ostream & outs()
Overwrite llvm::outs()
const SVFFunction * getProgEntryFunction()
Get program entry function.
void removeKey(const Key &key, KeySet &keySet)
Removes an element from a Set/CondSet (or anything implementing ::erase).
void insertKey(const Key &key, KeySet &keySet)
Inserts an element into a Set/CondSet (with ::insert).
void dumpPointsToList(const PointsToList &ptl)
std::set< Key, Compare, Allocator > OrderedSet
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
bool operator()(const NodeBS &lhs, const NodeBS &rhs) const
bool operator()(const PointsTo &lhs, const PointsTo &rhs) const
Type trait that checks if a type is iterable (can be applied on a range-based for loop)
Type trait to check if a type is a map or unordered_map.
Type trait to check if a type is vector or list.
Type trait to check if a type is a set or unordered_set.
void_t is not available until C++17. We define it here for C++11/14.