Skip to content

Commit

Permalink
Merge pull request #18 from whst/svf-1
Browse files Browse the repository at this point in the history
Refactor boilerplate code of disjunctive predicates of "isa()"
  • Loading branch information
yuleisui authored Nov 23, 2022
2 parents b3547f5 + 76811c7 commit e77428b
Show file tree
Hide file tree
Showing 22 changed files with 314 additions and 317 deletions.
12 changes: 4 additions & 8 deletions include/DDA/DDAVFSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,9 @@ class DDAVFSolver
{
handleAddr(pts,dpm,SVFUtil::cast<AddrSVFGNode>(node));
}
else if(SVFUtil::isa<CopySVFGNode>(node) || SVFUtil::isa<PHISVFGNode>(node)
|| SVFUtil::isa<ActualParmSVFGNode>(node) || SVFUtil::isa<FormalParmSVFGNode>(node)
|| SVFUtil::isa<ActualRetSVFGNode>(node) || SVFUtil::isa<FormalRetSVFGNode>(node)
|| SVFUtil::isa<NullPtrSVFGNode>(node))
else if (SVFUtil::isa<CopySVFGNode, PHISVFGNode, ActualParmSVFGNode,
FormalParmSVFGNode, ActualRetSVFGNode,
FormalRetSVFGNode, NullPtrSVFGNode>(node))
{
backtraceAlongDirectVF(pts,dpm);
}
Expand Down Expand Up @@ -579,10 +578,7 @@ class DDAVFSolver
/// Whether this is a top-level pointer statement
inline bool isTopLevelPtrStmt(const SVFGNode* stmt)
{
if (SVFUtil::isa<StoreSVFGNode>(stmt) || SVFUtil::isa<MRSVFGNode>(stmt))
return false;
else
return true;
return !SVFUtil::isa<StoreSVFGNode, MRSVFGNode>(stmt);
}
/// Return dpm with old context and path conditions
virtual inline DPIm getDPImWithOldCond(const DPIm& oldDpm,const CVar& var, const SVFGNode* loc)
Expand Down
4 changes: 2 additions & 2 deletions include/Graphs/SVFGOPT.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ class SVFGOPT : public SVFG
/// Return TRUE if both edges are indirect call/ret edges.
inline bool bothInterEdges(const SVFGEdge* edge1, const SVFGEdge* edge2) const
{
bool inter1 = (SVFUtil::isa<CallIndSVFGEdge>(edge1) || SVFUtil::isa<RetIndSVFGEdge>(edge1));
bool inter2 = (SVFUtil::isa<CallIndSVFGEdge>(edge2) || SVFUtil::isa<RetIndSVFGEdge>(edge2));
bool inter1 = SVFUtil::isa<CallIndSVFGEdge, RetIndSVFGEdge>(edge1);
bool inter2 = SVFUtil::isa<CallIndSVFGEdge, RetIndSVFGEdge>(edge2);
return (inter1 && inter2);
}

Expand Down
2 changes: 1 addition & 1 deletion include/MTA/MTAResultValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ class RaceResultValidator
I = I->getPrevNode();
while (I)
{
if (SVFUtil::isa<LoadInst>(I) || SVFUtil::isa<StoreInst>(I))
if (SVFUtil::isa<LoadInst, StoreInst>(I))
return I;

const SVFInstruction* inst = LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction(I);
Expand Down
32 changes: 23 additions & 9 deletions include/Util/Casting.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,27 @@ namespace SVFUtil
/// If T is a pointer to X, return a pointer to const X. If it is not,
/// return const T.
template<typename T, typename Enable = void>
struct add_const_past_pointer { using type = const T; };
struct add_const_past_pointer
{
using type = const T;
};

template <typename T>
struct add_const_past_pointer<T, std::enable_if_t<std::is_pointer<T>::value>>
struct add_const_past_pointer<T, std::enable_if_t<std::is_pointer<T>::value>>
{
using type = const std::remove_pointer_t<T> *;
using type = const std::remove_pointer_t<T> *;
};

/// If T is a pointer, just return it. If it is not, return T&.
template<typename T, typename Enable = void>
struct add_lvalue_reference_if_not_pointer { using type = T &; };
struct add_lvalue_reference_if_not_pointer
{
using type = T &;
};

template <typename T>
struct add_lvalue_reference_if_not_pointer<
T, std::enable_if_t<std::is_pointer<T>::value>>
T, std::enable_if_t<std::is_pointer<T>::value>>
{
using type = T;
};
Expand Down Expand Up @@ -230,13 +236,20 @@ struct isa_impl_wrap<To, FromTy, FromTy>
// template type argument. Used like this:
//
// if (SVFUtil::isa<Type>(myVal)) { ... }
// if (SVFUtil::isa<Type0, Type1, Type2>(myVal)) { ... }
//
template <class X, class Y> LLVM_NODISCARD inline bool isa(const Y &Val)
{
return isa_impl_wrap<X, const Y,
typename simplify_type<const Y>::SimpleType>::doit(Val);
}

template <typename First, typename Second, typename... Rest, typename Y>
LLVM_NODISCARD inline bool isa(const Y &Val)
{
return SVFUtil::isa<First>(Val) || SVFUtil::isa<Second, Rest...>(Val);
}

//===----------------------------------------------------------------------===//
// cast<x> Support Templates
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -343,8 +356,9 @@ template <class X> struct is_simple_type
//
template <class X, class Y>
inline std::enable_if_t<!is_simple_type<Y>::value,
typename cast_retty<X, const Y>::ret_type>
cast(const Y &Val) {
typename cast_retty<X, const Y>::ret_type>
cast(const Y &Val)
{
assert(SVFUtil::isa<X>(Val) && "cast<Ty>() argument of incompatible type!");
return cast_convert_val<
X, const Y, typename simplify_type<const Y>::SimpleType>::doit(Val);
Expand Down Expand Up @@ -387,8 +401,8 @@ inline typename cast_retty<X, std::unique_ptr<Y>>::ret_type

template <class X, class Y>
LLVM_NODISCARD inline std::enable_if_t<
!is_simple_type<Y>::value, typename cast_retty<X, const Y>::ret_type>
dyn_cast(const Y &Val)
!is_simple_type<Y>::value, typename cast_retty<X, const Y>::ret_type>
dyn_cast(const Y &Val)
{
return SVFUtil::isa<X>(Val) ? SVFUtil::cast<X>(Val) : nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/CFL/CFLStat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void CFLStat::CFLSolverStat()
*/
void CFLStat::performStat()
{
assert((SVFUtil::isa<CFLAlias>(pta)||SVFUtil::isa<CFLVF>(pta)) && "not an CFLAlias pass!! what else??");
assert((SVFUtil::isa<CFLAlias, CFLVF>(pta)) && "not an CFLAlias pass!! what else??");
endClk();

// Grammar stat
Expand Down
2 changes: 1 addition & 1 deletion lib/DDA/ContextDDA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ bool ContextDDA::isHeapCondMemObj(const CxtVar& var, const StoreSVFGNode*)
}
else
{
assert((SVFUtil::isa<DummyObjVar>(pnode) || SVFUtil::isa<DummyValVar>(pnode))
assert((SVFUtil::isa<DummyObjVar, DummyValVar>(pnode))
&& "empty refVal in non-dummy object");
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions lib/Graphs/ConsG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ bool ConstraintGraph::moveInEdgesToRepNode(ConstraintNode* node, ConstraintNode*
}
removeDirectEdge(edge);
}
else if(SVFUtil::isa<LoadCGEdge>(edge) || SVFUtil::isa<StoreCGEdge>(edge))
else if(SVFUtil::isa<LoadCGEdge, StoreCGEdge>(edge))
reTargetDstOfEdge(edge,rep);
else if(AddrCGEdge* addr = SVFUtil::dyn_cast<AddrCGEdge>(edge))
{
Expand Down Expand Up @@ -539,7 +539,7 @@ bool ConstraintGraph::moveOutEdgesToRepNode(ConstraintNode*node, ConstraintNode*
}
removeDirectEdge(edge);
}
else if(SVFUtil::isa<LoadCGEdge>(edge) || SVFUtil::isa<StoreCGEdge>(edge))
else if(SVFUtil::isa<LoadCGEdge, StoreCGEdge>(edge))
reTargetSrcOfEdge(edge,rep);
else if(AddrCGEdge* addr = SVFUtil::dyn_cast<AddrCGEdge>(edge))
{
Expand Down
32 changes: 15 additions & 17 deletions lib/Graphs/SVFGOPT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ void SVFGOPT::handleInterValueFlow()
it!=eit; ++it)
{
SVFGNode* node = it->second;
if (SVFUtil::isa<ActualParmSVFGNode>(node) || SVFUtil::isa<ActualRetSVFGNode>(node)
|| SVFUtil::isa<FormalParmSVFGNode>(node) || SVFUtil::isa<FormalRetSVFGNode>(node)
|| SVFUtil::isa<ActualINSVFGNode>(node) || SVFUtil::isa<ActualOUTSVFGNode>(node)
|| SVFUtil::isa<FormalINSVFGNode>(node) || SVFUtil::isa<FormalOUTSVFGNode>(node))
if (SVFUtil::isa<ActualParmSVFGNode, ActualRetSVFGNode, FormalParmSVFGNode,
FormalRetSVFGNode, ActualINSVFGNode, ActualOUTSVFGNode,
FormalINSVFGNode, FormalOUTSVFGNode>(node))
candidates.insert(node);
}

Expand All @@ -116,16 +115,16 @@ void SVFGOPT::handleInterValueFlow()
replaceFParamARetWithPHI(addInterPHIForAR(ar), ar);
nodesToBeDeleted.insert(ar);
}
else if (SVFUtil::isa<ActualParmSVFGNode>(node) || SVFUtil::isa<FormalRetSVFGNode>(node))
else if (SVFUtil::isa<ActualParmSVFGNode, FormalRetSVFGNode>(node))
{
nodesToBeDeleted.insert(node);
}
else if (SVFUtil::isa<ActualINSVFGNode>(node) || SVFUtil::isa<FormalOUTSVFGNode>(node))
else if (SVFUtil::isa<ActualINSVFGNode, FormalOUTSVFGNode>(node))
{
retargetEdgesOfAInFOut(node);
nodesToBeDeleted.insert(node);
}
else if (SVFUtil::isa<ActualOUTSVFGNode>(node) || SVFUtil::isa<FormalINSVFGNode>(node))
else if (SVFUtil::isa<ActualOUTSVFGNode, FormalINSVFGNode>(node))
{
if(keepActualOutFormalIn == false)
nodesToBeDeleted.insert(node);
Expand All @@ -137,7 +136,7 @@ void SVFGOPT::handleInterValueFlow()
SVFGNode* node = *it;
if (canBeRemoved(node))
{
if (SVFUtil::isa<ActualOUTSVFGNode>(node) || SVFUtil::isa<FormalINSVFGNode>(node))
if (SVFUtil::isa<ActualOUTSVFGNode, FormalINSVFGNode>(node))
retargetEdgesOfAOutFIn(node); /// reset def of address-taken variable

removeAllEdges(node);
Expand All @@ -151,7 +150,7 @@ void SVFGOPT::handleInterValueFlow()
*/
void SVFGOPT::replaceFParamARetWithPHI(PHISVFGNode* phi, SVFGNode* svfgNode)
{
assert((SVFUtil::isa<FormalParmSVFGNode>(svfgNode) || SVFUtil::isa<ActualRetSVFGNode>(svfgNode))
assert((SVFUtil::isa<FormalParmSVFGNode, ActualRetSVFGNode>(svfgNode))
&& "expecting a formal param or actual ret svfg node");

/// create a new PHISVFGNode.
Expand Down Expand Up @@ -299,7 +298,7 @@ bool SVFGOPT::isConnectingTwoCallSites(const SVFGNode* node) const
SVFGNode::const_iterator edgeEit = node->InEdgeEnd();
for (; edgeIt != edgeEit; ++edgeIt)
{
if (SVFUtil::isa<CallIndSVFGEdge>(*edgeIt) || SVFUtil::isa<RetIndSVFGEdge>(*edgeIt))
if (SVFUtil::isa<CallIndSVFGEdge, RetIndSVFGEdge>(*edgeIt))
{
hasInCallRet = true;
break;
Expand All @@ -310,7 +309,7 @@ bool SVFGOPT::isConnectingTwoCallSites(const SVFGNode* node) const
edgeEit = node->OutEdgeEnd();
for (; edgeIt != edgeEit; ++edgeIt)
{
if (SVFUtil::isa<CallIndSVFGEdge>(*edgeIt) || SVFUtil::isa<RetIndSVFGEdge>(*edgeIt))
if (SVFUtil::isa<CallIndSVFGEdge, RetIndSVFGEdge>(*edgeIt))
{
hasOutCallRet = true;
break;
Expand All @@ -334,12 +333,11 @@ bool SVFGOPT::isConnectingTwoCallSites(const SVFGNode* node) const
/// 5. FormalOUT if it doesn't reside at the exit of address-taken function
bool SVFGOPT::canBeRemoved(const SVFGNode * node)
{
if (SVFUtil::isa<ActualParmSVFGNode>(node) || SVFUtil::isa<FormalParmSVFGNode>(node)
|| SVFUtil::isa<ActualRetSVFGNode>(node) || SVFUtil::isa<FormalRetSVFGNode>(node))
if (SVFUtil::isa<ActualParmSVFGNode, FormalParmSVFGNode,
ActualRetSVFGNode, FormalRetSVFGNode>(node))
return true;
else if (SVFUtil::isa<ActualINSVFGNode>(node) || SVFUtil::isa<ActualOUTSVFGNode>(node)
|| SVFUtil::isa<FormalINSVFGNode>(node) || SVFUtil::isa<FormalOUTSVFGNode>(node)
|| SVFUtil::isa<MSSAPHISVFGNode>(node))
else if (SVFUtil::isa<ActualINSVFGNode, ActualOUTSVFGNode, FormalINSVFGNode,
FormalOUTSVFGNode, MSSAPHISVFGNode>(node))
{
/// Now each SVFG edge can only be associated with one call site id,
/// so if this node has both incoming call/ret and outgoting call/ret
Expand Down Expand Up @@ -460,7 +458,7 @@ bool SVFGOPT::checkSelfCycleEdges(const MSSAPHISVFGNode* node)
break; /// There's no need to check other edge if we do not remove self cycle
}
else if (keepContextSelfCycle &&
(SVFUtil::isa<CallIndSVFGEdge>(preEdge) || SVFUtil::isa<RetIndSVFGEdge>(preEdge)))
SVFUtil::isa<CallIndSVFGEdge, RetIndSVFGEdge>(preEdge))
{
hasSelfCycle = true;
continue; /// Continue checking and remove other self cycle which are NOT context-related
Expand Down
13 changes: 7 additions & 6 deletions lib/MTA/FSMPTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ bool MTASVFGBuilder::isTailofSpan(const StmtSVFGNode* n, InstSet mergespan)

for (SVFGNodeIDSet::iterator it = succ.begin(), eit = succ.end(); it != eit; ++it)
{
assert ((SVFUtil::isa<StoreSVFGNode>(svfg->getSVFGNode(*it)) || SVFUtil::isa<LoadSVFGNode>(svfg->getSVFGNode(*it))) && "succ is not a store/load node");
assert((SVFUtil::isa<StoreSVFGNode, LoadSVFGNode>(svfg->getSVFGNode(*it))) &&
"succ is not a store/load node");
const StmtSVFGNode* succNode = SVFUtil::dyn_cast<StmtSVFGNode>(svfg->getSVFGNode(*it));
const SVFInstruction* succIns = succNode->getInst();

Expand All @@ -292,7 +293,8 @@ bool MTASVFGBuilder::isTailofSpan(const StmtSVFGNode* n, LockAnalysis::LockSpan
SVFGNodeIDSet succ = getSuccNodes(n);
for (SVFGNodeIDSet::iterator it = succ.begin(), eit = succ.end(); it != eit; ++it)
{
assert ((SVFUtil::isa<StoreSVFGNode>(svfg->getSVFGNode(*it)) || SVFUtil::isa<LoadSVFGNode>(svfg->getSVFGNode(*it))) && "succ is not a store/load node");
assert((SVFUtil::isa<StoreSVFGNode, LoadSVFGNode>(svfg->getSVFGNode(*it))) &&
"succ is not a store/load node");
if (SVFUtil::isa<LoadSVFGNode>(svfg->getSVFGNode(*it)))
continue;
const StmtSVFGNode* succNode = SVFUtil::dyn_cast<StmtSVFGNode>(svfg->getSVFGNode(*it));
Expand Down Expand Up @@ -322,8 +324,7 @@ bool MTASVFGBuilder::isTailofSpan(const StmtSVFGNode* n)

for (SVFGNodeIDSet::iterator it = succ.begin(), eit = succ.end(); it != eit; ++it)
{
assert((SVFUtil::isa<StoreSVFGNode>(svfg->getSVFGNode(*it)) || SVFUtil::isa<LoadSVFGNode>(svfg->getSVFGNode(*it)))
&& "succ is not a store/load node");
assert((SVFUtil::isa<StoreSVFGNode, LoadSVFGNode>(svfg->getSVFGNode(*it))) && "succ is not a store/load node");
if (SVFUtil::isa<LoadSVFGNode>(svfg->getSVFGNode(*it)))
continue;

Expand Down Expand Up @@ -401,7 +402,7 @@ MTASVFGBuilder::SVFGNodeIDSet MTASVFGBuilder::getSuccNodes(const StmtSVFGNode* n
const SVFGNode* node = *worklist.begin();
worklist.erase(worklist.begin());
visited.insert(node);
if (SVFUtil::isa<StoreSVFGNode>(node) || SVFUtil::isa<LoadSVFGNode>(node))
if (SVFUtil::isa<StoreSVFGNode, LoadSVFGNode>(node))
succ.set(node->getId());
else
{
Expand Down Expand Up @@ -440,7 +441,7 @@ MTASVFGBuilder::SVFGNodeIDSet MTASVFGBuilder::getSuccNodes(const StmtSVFGNode* n
const SVFGNode* node = *worklist.begin();
worklist.erase(worklist.begin());
visited.insert(node);
if (SVFUtil::isa<StoreSVFGNode>(node) || SVFUtil::isa<LoadSVFGNode>(node))
if (SVFUtil::isa<StoreSVFGNode, LoadSVFGNode>(node))
succ.set(node->getId());
else
{
Expand Down
2 changes: 1 addition & 1 deletion lib/MTA/LockAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ void LockAnalysis::handleRet(const CxtStmt& cts)
for (PTACallGraphNode::const_iterator it = curFunNode->getInEdges().begin(), eit = curFunNode->getInEdges().end(); it != eit; ++it)
{
PTACallGraphEdge* edge = *it;
if (SVFUtil::isa<ThreadForkEdge>(edge) || SVFUtil::isa<ThreadJoinEdge>(edge))
if (SVFUtil::isa<ThreadForkEdge, ThreadJoinEdge>(edge))
continue;
for (PTACallGraphEdge::CallInstSet::const_iterator cit = (edge)->directCallsBegin(), ecit = (edge)->directCallsEnd(); cit != ecit;
++cit)
Expand Down
Loading

0 comments on commit e77428b

Please sign in to comment.