diff --git a/svf-llvm/lib/ICFGBuilder.cpp b/svf-llvm/lib/ICFGBuilder.cpp index 726ddd06c..985f7c0dc 100644 --- a/svf-llvm/lib/ICFGBuilder.cpp +++ b/svf-llvm/lib/ICFGBuilder.cpp @@ -157,7 +157,7 @@ void ICFGBuilder::processFunBody(WorkList& worklist) } InstVec nextInsts; LLVMUtil::getNextInsts(inst, nextInsts); - u32_t branchID = 0; + s64_t branchID = 0; for (InstVec::const_iterator nit = nextInsts.begin(), enit = nextInsts.end(); nit != enit; ++nit) { @@ -185,7 +185,7 @@ void ICFGBuilder::processFunBody(WorkList& worklist) { assert(branchID <= 1 && "if/else has more than two branches?"); if(br->isConditional()) - icfg->addConditionalIntraEdge(srcNode, dstNode, llvmModuleSet()->getSVFValue(br->getCondition()), 1 - branchID); + icfg->addConditionalIntraEdge(srcNode, dstNode, 1 - branchID); else icfg->addIntraEdge(srcNode, dstNode); } @@ -197,7 +197,7 @@ void ICFGBuilder::processFunBody(WorkList& worklist) s64_t val = -1; if (condVal && condVal->getBitWidth() <= 64) val = condVal->getSExtValue(); - icfg->addConditionalIntraEdge(srcNode, dstNode, llvmModuleSet()->getSVFValue(si->getCondition()),val); + icfg->addConditionalIntraEdge(srcNode, dstNode,val); } else icfg->addIntraEdge(srcNode, dstNode); diff --git a/svf-llvm/lib/SVFIRBuilder.cpp b/svf-llvm/lib/SVFIRBuilder.cpp index 7c5e1b544..24aa1198f 100644 --- a/svf-llvm/lib/SVFIRBuilder.cpp +++ b/svf-llvm/lib/SVFIRBuilder.cpp @@ -975,6 +975,17 @@ void SVFIRBuilder::visitBranchInst(BranchInst &inst) branchID++; } addBranchStmt(brinst, cond, successors); + /// set conditional svf var + if (inst.isConditional()) + { + for (auto& edge : llvmModuleSet()->getICFGNode(&inst)->getOutEdges()) + { + if (IntraCFGEdge* intraEdge = SVFUtil::dyn_cast(edge)) + { + intraEdge->setConditionVar(pag->getGNode(cond)); + } + } + } } @@ -1043,6 +1054,14 @@ void SVFIRBuilder::visitSwitchInst(SwitchInst &inst) successors.push_back(std::make_pair(icfgNode, val)); } addBranchStmt(brinst, cond, successors); + /// set conditional svf var + for (auto& edge : llvmModuleSet()->getICFGNode(&inst)->getOutEdges()) + { + if (IntraCFGEdge* intraEdge = SVFUtil::dyn_cast(edge)) + { + intraEdge->setConditionVar(pag->getGNode(cond)); + } + } } diff --git a/svf/include/Graphs/ICFG.h b/svf/include/Graphs/ICFG.h index 11c4ee4ce..747a10c8b 100644 --- a/svf/include/Graphs/ICFG.h +++ b/svf/include/Graphs/ICFG.h @@ -143,7 +143,7 @@ class ICFG : public GenericICFGTy /// Add intraprocedural and interprocedural control-flow edges. //@{ ICFGEdge* addIntraEdge(ICFGNode* srcNode, ICFGNode* dstNode); - ICFGEdge* addConditionalIntraEdge(ICFGNode* srcNode, ICFGNode* dstNode, const SVFValue* condition, s32_t branchCondVal); + ICFGEdge* addConditionalIntraEdge(ICFGNode* srcNode, ICFGNode* dstNode, s64_t branchCondVal); ICFGEdge* addCallEdge(ICFGNode* srcNode, ICFGNode* dstNode); ICFGEdge* addRetEdge(ICFGNode* srcNode, ICFGNode* dstNode); //@} diff --git a/svf/include/Graphs/ICFGEdge.h b/svf/include/Graphs/ICFGEdge.h index 2530e76d5..e433696b6 100644 --- a/svf/include/Graphs/ICFGEdge.h +++ b/svf/include/Graphs/ICFGEdge.h @@ -114,6 +114,8 @@ class IntraCFGEdge : public ICFGEdge { friend class SVFIRWriter; friend class SVFIRReader; + friend class ICFG; + friend class SVFIRBuilder; public: /// Constructor @@ -137,7 +139,7 @@ class IntraCFGEdge : public ICFGEdge } //@} - const SVFValue* getCondition() const + const SVFVar* getCondition() const { return conditionVar; } @@ -148,12 +150,6 @@ class IntraCFGEdge : public ICFGEdge return branchCondVal; } - void setBranchCondition(const SVFValue* c, s64_t bVal) - { - conditionVar = c; - branchCondVal = bVal; - } - virtual const std::string toString() const; private: @@ -166,8 +162,18 @@ class IntraCFGEdge : public ICFGEdge /// Inst3: label 1; /// for edge between Inst1 and Inst 2, the first element is %cmp and /// the second element is 0 - const SVFValue* conditionVar; + const SVFVar* conditionVar; s64_t branchCondVal; + + inline void setConditionVar(const SVFVar* c) + { + conditionVar = c; + } + + inline void setBranchCondVal(s64_t bVal) + { + branchCondVal = bVal; + } }; /*! diff --git a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp index 9514e2b14..8ea21a40a 100644 --- a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp +++ b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp @@ -452,9 +452,7 @@ bool AbstractInterpretation::isSwitchBranchFeasible(const SVFVar* var, s64_t suc bool AbstractInterpretation::isBranchFeasible(const IntraCFGEdge* intraEdge, AbstractState& as) { - const SVFValue *cond = intraEdge->getCondition(); - NodeID cmpID = svfir->getValueNode(cond); - SVFVar *cmpVar = svfir->getGNode(cmpID); + const SVFVar *cmpVar = intraEdge->getCondition(); if (cmpVar->getInEdges().empty()) { return isSwitchBranchFeasible(cmpVar, diff --git a/svf/lib/Graphs/ICFG.cpp b/svf/lib/Graphs/ICFG.cpp index 34e1deb9c..7e99b720c 100644 --- a/svf/lib/Graphs/ICFG.cpp +++ b/svf/lib/Graphs/ICFG.cpp @@ -341,7 +341,7 @@ ICFGEdge* ICFG::addIntraEdge(ICFGNode* srcNode, ICFGNode* dstNode) /*! * Add conditional intraprocedural edges between two nodes */ -ICFGEdge* ICFG::addConditionalIntraEdge(ICFGNode* srcNode, ICFGNode* dstNode, const SVFValue* condition, s32_t branchCondVal) +ICFGEdge* ICFG::addConditionalIntraEdge(ICFGNode* srcNode, ICFGNode* dstNode, s64_t branchCondVal) { checkIntraEdgeParents(srcNode, dstNode); @@ -354,7 +354,7 @@ ICFGEdge* ICFG::addConditionalIntraEdge(ICFGNode* srcNode, ICFGNode* dstNode, co else { IntraCFGEdge* intraEdge = new IntraCFGEdge(srcNode,dstNode); - intraEdge->setBranchCondition(condition,branchCondVal); + intraEdge->setBranchCondVal(branchCondVal); return (addICFGEdge(intraEdge) ? intraEdge : nullptr); } }