From e1bd48f7bd09746c9b500c76452c7fe744c7e899 Mon Sep 17 00:00:00 2001 From: jumormt Date: Fri, 10 Jan 2025 14:47:21 +1100 Subject: [PATCH] change position of param to make it more logical --- svf-llvm/lib/SVFIRBuilder.cpp | 30 +++++++++++-------------- svf-llvm/lib/SVFIRExtAPI.cpp | 2 +- svf/include/SVFIR/SVFIR.h | 38 ++++++++++++++++---------------- svf/include/SVFIR/SVFVariables.h | 24 ++++++++++---------- svf/lib/SVFIR/SVFIR.cpp | 4 ++-- svf/lib/SVFIR/SVFVariables.cpp | 14 +++++------- 6 files changed, 53 insertions(+), 59 deletions(-) diff --git a/svf-llvm/lib/SVFIRBuilder.cpp b/svf-llvm/lib/SVFIRBuilder.cpp index 994fd084e..23d5725ad 100644 --- a/svf-llvm/lib/SVFIRBuilder.cpp +++ b/svf-llvm/lib/SVFIRBuilder.cpp @@ -243,10 +243,8 @@ void SVFIRBuilder::initialiseNodes() { const CallGraphNode* cgn = llvmModuleSet()->getCallGraphNode(func); // add value node representing the function - pag->addFunValNode(cgn, iter->second, icfgNode); - } - else if (auto argval = SVFUtil::dyn_cast(llvmValue)) - { + pag->addFunValNode(iter->second, icfgNode, cgn); + } else if (auto argval = SVFUtil::dyn_cast(llvmValue)) { pag->addArgValNode( iter->second, argval->getArgNo(), icfgNode, llvmModuleSet()->getCallGraphNode(argval->getParent()), @@ -256,13 +254,13 @@ void SVFIRBuilder::initialiseNodes() } else if (auto fpValue = SVFUtil::dyn_cast(llvmValue)) { - pag->addConstantFPValNode(iter->first, LLVMUtil::getDoubleValue(fpValue), iter->second, icfgNode); + pag->addConstantFPValNode(iter->first, iter->second, LLVMUtil::getDoubleValue(fpValue), icfgNode); llvmModuleSet()->addToLLVMVal2SVFVarMap( fpValue, pag->getGNode(iter->second)); } else if (auto intValue = SVFUtil::dyn_cast(llvmValue)) { - pag->addConstantIntValNode(iter->first, LLVMUtil::getIntegerValue(intValue), iter->second, icfgNode); + pag->addConstantIntValNode(iter->first, iter->second, LLVMUtil::getIntegerValue(intValue), icfgNode); llvmModuleSet()->addToLLVMVal2SVFVarMap( intValue, pag->getGNode(iter->second)); } @@ -309,14 +307,14 @@ void SVFIRBuilder::initialiseNodes() // Check if the value is a function and add a function object node if (const Function* func = SVFUtil::dyn_cast(llvmValue)) { - pag->addFunObjNode(llvmModuleSet()->getCallGraphNode(func), iter->second); + pag->addFunObjNode(iter->second, llvmModuleSet()->getCallGraphNode(func)); } // Check if the value is a heap object and add a heap object node else if (LLVMUtil::isHeapObj(llvmValue)) { const SVFFunction* f = SVFUtil::cast(iter->first)->getFunction(); - pag->addHeapObjNode(iter->first, f, iter->second); + pag->addHeapObjNode(iter->first, iter->second, f); llvmModuleSet()->addToLLVMVal2SVFVarMap( llvmValue, pag->getGNode(iter->second)); } @@ -325,19 +323,19 @@ void SVFIRBuilder::initialiseNodes() { const SVFFunction* f = SVFUtil::cast(iter->first)->getFunction(); - pag->addStackObjNode(iter->first, f, iter->second); + pag->addStackObjNode(iter->first, iter->second, f); llvmModuleSet()->addToLLVMVal2SVFVarMap( llvmValue, pag->getGNode(iter->second)); } else if (auto fpValue = SVFUtil::dyn_cast(llvmValue)) { - pag->addConstantFPObjNode(iter->first, LLVMUtil::getDoubleValue(fpValue), iter->second); + pag->addConstantFPObjNode(iter->first, iter->second, LLVMUtil::getDoubleValue(fpValue)); llvmModuleSet()->addToLLVMVal2SVFVarMap( fpValue, pag->getGNode(iter->second)); } else if (auto intValue = SVFUtil::dyn_cast(llvmValue)) { - pag->addConstantIntObjNode(iter->first, LLVMUtil::getIntegerValue(intValue), iter->second); + pag->addConstantIntObjNode(iter->first, iter->second, LLVMUtil::getIntegerValue(intValue)); llvmModuleSet()->addToLLVMVal2SVFVarMap( intValue, pag->getGNode(iter->second)); } @@ -371,10 +369,9 @@ void SVFIRBuilder::initialiseNodes() ++iter) { DBOUT(DPAGBuild, outs() << "add ret node " << iter->second << "\n"); - pag->addRetNode( + pag->addRetNode(iter->second, llvmModuleSet()->getCallGraphNode(SVFUtil::cast( - llvmModuleSet()->getLLVMValue(iter->first))), - iter->second); + llvmModuleSet()->getLLVMValue(iter->first)))); } for (SymbolTableInfo::FunToIDMapTy::iterator iter = @@ -382,10 +379,9 @@ void SVFIRBuilder::initialiseNodes() iter != symTable->varargSyms().end(); ++iter) { DBOUT(DPAGBuild, outs() << "add vararg node " << iter->second << "\n"); - pag->addVarargNode( + pag->addVarargNode(iter->second, llvmModuleSet()->getCallGraphNode(SVFUtil::cast( - llvmModuleSet()->getLLVMValue(iter->first))), - iter->second); + llvmModuleSet()->getLLVMValue(iter->first)))); } /// add address edges for constant nodes. diff --git a/svf-llvm/lib/SVFIRExtAPI.cpp b/svf-llvm/lib/SVFIRExtAPI.cpp index 3c55368c8..04314ccf8 100644 --- a/svf-llvm/lib/SVFIRExtAPI.cpp +++ b/svf-llvm/lib/SVFIRExtAPI.cpp @@ -65,7 +65,7 @@ const Type* SVFIRBuilder::getBaseTypeAndFlattenedFields(const Value* V, std::vec { SymbolTableBuilder builder(pag->getSymbolInfo()); builder.collectSym(offset); - pag->addConstantIntValNode(svfOffset, LLVMUtil::getIntegerValue(offset), pag->getSymbolInfo()->getValSym(svfOffset), nullptr); + pag->addConstantIntValNode(svfOffset, pag->getSymbolInfo()->getValSym(svfOffset), LLVMUtil::getIntegerValue(offset), nullptr); } ls.addOffsetVarAndGepTypePair(getPAG()->getGNode(getPAG()->getValueNode(svfOffset)), nullptr); fields.push_back(ls); diff --git a/svf/include/SVFIR/SVFIR.h b/svf/include/SVFIR/SVFIR.h index 0376d0a7d..ae0a34930 100644 --- a/svf/include/SVFIR/SVFIR.h +++ b/svf/include/SVFIR/SVFIR.h @@ -572,9 +572,9 @@ class SVFIR : public IRGraph return addValNode(val, node, i); } - NodeID addFunValNode(const CallGraphNode* callGraphNode, NodeID i, const ICFGNode* icfgNode) + NodeID addFunValNode(NodeID i, const ICFGNode* icfgNode, const CallGraphNode* callGraphNode) { - FunValVar* node = new FunValVar(callGraphNode, i, icfgNode); + FunValVar* node = new FunValVar(i, icfgNode, callGraphNode); return addValNode(nullptr, node, i); } @@ -585,17 +585,17 @@ class SVFIR : public IRGraph return addValNode(nullptr, node, i); } - inline NodeID addConstantFPValNode(const SVFValue* curInst, double dval, const NodeID i, + inline NodeID addConstantFPValNode(const SVFValue* curInst, const NodeID i, double dval, const ICFGNode* icfgNode) { - SVFVar* node = new ConstantFPValVar(curInst, dval, i, icfgNode); + SVFVar* node = new ConstantFPValVar(curInst, i, dval, icfgNode); return addNode(node, i); } - inline NodeID addConstantIntValNode(const SVFValue* curInst, const std::pair& intValue, const NodeID i, + inline NodeID addConstantIntValNode(const SVFValue* curInst, NodeID i, const std::pair& intValue, const ICFGNode* icfgNode) { - SVFVar* node = new ConstantIntValVar(curInst, intValue.first, intValue.second, i, icfgNode); + SVFVar* node = new ConstantIntValVar(curInst, i, intValue.first, intValue.second, icfgNode); return addNode(node, i); } @@ -629,47 +629,47 @@ class SVFIR : public IRGraph /** * Creates and adds a heap object node to the SVFIR */ - inline NodeID addHeapObjNode(const SVFValue* val, const SVFFunction* f, NodeID i) + inline NodeID addHeapObjNode(const SVFValue* val, NodeID i, const SVFFunction* f) { const MemObj* mem = getMemObj(val); assert(mem->getId() == i && "not same object id?"); memToFieldsMap[i].set(i); - HeapObjVar *node = new HeapObjVar(f, val->getType(), i, mem); + HeapObjVar *node = new HeapObjVar(i, mem, val->getType(), f); return addObjNode(val, node, i); } /** * Creates and adds a stack object node to the SVFIR */ - inline NodeID addStackObjNode(const SVFValue* val, const SVFFunction* f, NodeID i) + inline NodeID addStackObjNode(const SVFValue* val, NodeID i, const SVFFunction* f) { const MemObj* mem = getMemObj(val); assert(mem->getId() == i && "not same object id?"); memToFieldsMap[i].set(i); - StackObjVar *node = new StackObjVar(f, val->getType(), i, mem); + StackObjVar *node = new StackObjVar(i, mem, val->getType(), f); return addObjNode(val, node, i); } - NodeID addFunObjNode(const CallGraphNode* callGraphNode, NodeID id); + NodeID addFunObjNode(NodeID id, const CallGraphNode* callGraphNode); - inline NodeID addConstantFPObjNode(const SVFValue* curInst, double dval, const NodeID i) + inline NodeID addConstantFPObjNode(const SVFValue* curInst, NodeID i, double dval) { const MemObj* mem = getMemObj(curInst); NodeID base = mem->getId(); memToFieldsMap[base].set(mem->getId()); - ConstantFPObjVar* node = new ConstantFPObjVar(curInst, dval, mem->getId(), mem); + ConstantFPObjVar* node = new ConstantFPObjVar(curInst, i, dval, mem); return addObjNode(curInst, node, mem->getId()); } - inline NodeID addConstantIntObjNode(const SVFValue* curInst, const std::pair& intValue, const NodeID i) + inline NodeID addConstantIntObjNode(const SVFValue* curInst, NodeID i, const std::pair& intValue) { const MemObj* mem = getMemObj(curInst); NodeID base = mem->getId(); memToFieldsMap[base].set(mem->getId()); ConstantIntObjVar* node = - new ConstantIntObjVar(curInst, intValue.first, intValue.second, mem->getId(), mem); + new ConstantIntObjVar(curInst, i, intValue.first, intValue.second, mem); return addObjNode(curInst, node, mem->getId()); } @@ -702,15 +702,15 @@ class SVFIR : public IRGraph } /// Add a unique return node for a procedure - inline NodeID addRetNode(const CallGraphNode* callGraphNode, NodeID i) + inline NodeID addRetNode(NodeID i, const CallGraphNode* callGraphNode) { - SVFVar *node = new RetPN(callGraphNode,i); + SVFVar *node = new RetPN(i, callGraphNode); return addRetNode(callGraphNode, node, i); } /// Add a unique vararg node for a procedure - inline NodeID addVarargNode(const CallGraphNode* val, NodeID i) + inline NodeID addVarargNode(NodeID i, const CallGraphNode* val) { - SVFVar *node = new VarArgPN(val,i); + SVFVar *node = new VarArgPN(i, val); return addNode(node,i); } diff --git a/svf/include/SVFIR/SVFVariables.h b/svf/include/SVFIR/SVFVariables.h index 487009553..8e3fb78a4 100644 --- a/svf/include/SVFIR/SVFVariables.h +++ b/svf/include/SVFIR/SVFVariables.h @@ -724,8 +724,8 @@ class HeapObjVar: public BaseObjVar //@} /// Constructor - HeapObjVar(const SVFFunction* func, const SVFType* svfType, NodeID i, - const MemObj* mem, PNODEK ty = HeapObjNode); + HeapObjVar(NodeID i, const MemObj* mem, const SVFType* svfType, + const SVFFunction* fun, PNODEK ty = HeapObjNode); /// Return name of a LLVM value inline const std::string getValueName() const @@ -785,8 +785,8 @@ class StackObjVar: public BaseObjVar //@} /// Constructor - StackObjVar(const SVFFunction* f, const SVFType* svfType, NodeID i, - const MemObj* mem, PNODEK ty = StackObjNode); + StackObjVar(NodeID i, const MemObj* mem, const SVFType* svfType, + const SVFFunction* fun, PNODEK ty = StackObjNode); /// Return name of a LLVM value inline const std::string getValueName() const @@ -838,7 +838,7 @@ class FunValVar : public ValVar } /// Constructor - FunValVar(const CallGraphNode* cgn, NodeID i, const ICFGNode* icn, + FunValVar(NodeID i, const ICFGNode* icn, const CallGraphNode* cgn, PNODEK ty = FunValNode); virtual const std::string toString() const; @@ -886,7 +886,7 @@ class FunObjVar : public BaseObjVar //@} /// Constructor - FunObjVar(const CallGraphNode* cgNode, NodeID i, const MemObj* mem, + FunObjVar(NodeID i, const MemObj* mem, const CallGraphNode* cgNode, PNODEK ty = FunObjNode); inline const CallGraphNode* getCallGraphNode() const @@ -1069,7 +1069,7 @@ class ConstantFPValVar: public ConstantDataValVar } /// Constructor - ConstantFPValVar(const SVFValue* val, double dv, NodeID i, const ICFGNode* icn, + ConstantFPValVar(const SVFValue* val, NodeID i, double dv, const ICFGNode* icn, PNODEK ty = ConstantFPValNode) : ConstantDataValVar(val, i, icn, ty), dval(dv) { @@ -1128,7 +1128,7 @@ class ConstantIntValVar: public ConstantDataValVar } /// Constructor - ConstantIntValVar(const SVFValue* val, s64_t sv, u64_t zv, NodeID i, const ICFGNode* icn, + ConstantIntValVar(const SVFValue* val, NodeID i, s64_t sv, u64_t zv, const ICFGNode* icn, PNODEK ty = ConstantIntValNode) : ConstantDataValVar(val, i, icn, ty), zval(zv), sval(sv) { @@ -1327,7 +1327,7 @@ class ConstantFPObjVar: public ConstantDataObjVar //@} /// Constructor - ConstantFPObjVar(const SVFValue* val, double dv, NodeID i, const MemObj* m, PNODEK ty = ConstantFPObjNode) + ConstantFPObjVar(const SVFValue* val, NodeID i, double dv, const MemObj* m, PNODEK ty = ConstantFPObjNode) : ConstantDataObjVar(val, i, m, ty), dval(dv) { } @@ -1402,7 +1402,7 @@ class ConstantIntObjVar: public ConstantDataObjVar //@} /// Constructor - ConstantIntObjVar(const SVFValue* val, s64_t sv, u64_t zv, NodeID i, const MemObj* m, PNODEK ty = ConstantIntObjNode) + ConstantIntObjVar(const SVFValue* val, NodeID i, s64_t sv, u64_t zv, const MemObj* m, PNODEK ty = ConstantIntObjNode) : ConstantDataObjVar(val, i, m, ty), zval(zv), sval(sv) { } @@ -1505,7 +1505,7 @@ class RetPN: public ValVar /// Constructor - RetPN(const CallGraphNode* node, NodeID i); + RetPN(NodeID i, const CallGraphNode* node); inline const CallGraphNode* getCallGraphNode() const { @@ -1559,7 +1559,7 @@ class VarArgPN: public ValVar //@} /// Constructor - VarArgPN(const CallGraphNode* node, NodeID i) : ValVar(nullptr, i, VarargNode), callGraphNode(node) {} + VarArgPN(NodeID i, const CallGraphNode* node) : ValVar(nullptr, i, VarargNode), callGraphNode(node) {} virtual const SVFFunction* getFunction() const; diff --git a/svf/lib/SVFIR/SVFIR.cpp b/svf/lib/SVFIR/SVFIR.cpp index 12621c98b..42376aa91 100644 --- a/svf/lib/SVFIR/SVFIR.cpp +++ b/svf/lib/SVFIR/SVFIR.cpp @@ -472,14 +472,14 @@ NodeID SVFIR::addFIObjNode(const MemObj* obj) return addObjNode(obj->getValue(), node, obj->getId()); } -NodeID SVFIR::addFunObjNode(const CallGraphNode* callGraphNode, NodeID id) +NodeID SVFIR::addFunObjNode(NodeID id, const CallGraphNode* callGraphNode) { const MemObj* mem = getMemObj(callGraphNode->getFunction()); assert(mem->getId() == id && "not same object id?"); //assert(findPAGNode(i) == false && "this node should not be created before"); NodeID base = mem->getId(); memToFieldsMap[base].set(mem->getId()); - FunObjVar*node = new FunObjVar(callGraphNode, mem->getId(), mem); + FunObjVar*node = new FunObjVar(id, mem, callGraphNode); return addObjNode(mem->getValue(), node, mem->getId()); } diff --git a/svf/lib/SVFIR/SVFVariables.cpp b/svf/lib/SVFIR/SVFVariables.cpp index f70053d31..8fcec4d6d 100644 --- a/svf/lib/SVFIR/SVFVariables.cpp +++ b/svf/lib/SVFIR/SVFVariables.cpp @@ -191,7 +191,7 @@ const std::string GepValVar::toString() const return rawstr.str(); } -RetPN::RetPN(const CallGraphNode* node, NodeID i) : ValVar(i, RetNode), callGraphNode(node) +RetPN::RetPN(NodeID i, const CallGraphNode* node) : ValVar(i, RetNode), callGraphNode(node) { isPtr = node->getFunction()->getReturnType()->isPointerTy(); } @@ -232,8 +232,8 @@ const std::string BaseObjVar::toString() const return rawstr.str(); } -HeapObjVar::HeapObjVar(const SVFFunction* f, const SVFType* svfType, NodeID i, - const MemObj* mem, PNODEK ty) +HeapObjVar::HeapObjVar(NodeID i, const MemObj* mem, const SVFType* svfType, + const SVFFunction* f, PNODEK ty) : BaseObjVar(mem->getValue(), i, mem, ty) { isPtr = svfType->isPointerTy(); @@ -253,8 +253,7 @@ const std::string HeapObjVar::toString() const return rawstr.str(); } -StackObjVar::StackObjVar(const SVFFunction* f, const SVFType* svfType, NodeID i, - const MemObj* mem, PNODEK ty) +StackObjVar::StackObjVar(NodeID i, const MemObj* mem, const SVFType* svfType, const SVFFunction* f, PNODEK ty) : BaseObjVar(mem->getValue(), i, mem, ty) { isPtr = svfType->isPointerTy(); @@ -276,8 +275,7 @@ const std::string StackObjVar::toString() const -FunValVar::FunValVar(const CallGraphNode* cgn, NodeID i, const ICFGNode* icn, - PNODEK ty) +FunValVar::FunValVar(NodeID i, const ICFGNode* icn, const CallGraphNode* cgn, PNODEK ty) : ValVar(cgn->getFunction(), i, ty, icn), callGraphNode(cgn) { isPtr = cgn->getFunction()->getType()->isPointerTy(); @@ -426,7 +424,7 @@ const std::string ConstantNullPtrObjVar::toString() const return rawstr.str(); } -FunObjVar::FunObjVar(const CallGraphNode* cgNode, NodeID i, const MemObj* mem, +FunObjVar::FunObjVar(NodeID i, const MemObj* mem, const CallGraphNode* cgNode, PNODEK ty) : BaseObjVar(mem->getValue(), i, mem, ty), callGraphNode(cgNode) {