Skip to content

Commit

Permalink
Merge pull request #1627 from jumormt/1.10
Browse files Browse the repository at this point in the history
change position of param to make it more logical
  • Loading branch information
yuleisui authored Jan 10, 2025
2 parents 2b73b01 + e1bd48f commit a837b3f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 59 deletions.
30 changes: 13 additions & 17 deletions svf-llvm/lib/SVFIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Argument>(llvmValue))
{
pag->addFunValNode(iter->second, icfgNode, cgn);
} else if (auto argval = SVFUtil::dyn_cast<Argument>(llvmValue)) {
pag->addArgValNode(
iter->second, argval->getArgNo(), icfgNode,
llvmModuleSet()->getCallGraphNode(argval->getParent()),
Expand All @@ -256,13 +254,13 @@ void SVFIRBuilder::initialiseNodes()
}
else if (auto fpValue = SVFUtil::dyn_cast<ConstantFP>(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<ConstantInt>(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));
}
Expand Down Expand Up @@ -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<Function>(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<SVFInstruction>(iter->first)->getFunction();
pag->addHeapObjNode(iter->first, f, iter->second);
pag->addHeapObjNode(iter->first, iter->second, f);
llvmModuleSet()->addToLLVMVal2SVFVarMap(
llvmValue, pag->getGNode(iter->second));
}
Expand All @@ -325,19 +323,19 @@ void SVFIRBuilder::initialiseNodes()
{
const SVFFunction* f =
SVFUtil::cast<SVFInstruction>(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<ConstantFP>(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<ConstantInt>(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));
}
Expand Down Expand Up @@ -371,21 +369,19 @@ void SVFIRBuilder::initialiseNodes()
++iter)
{
DBOUT(DPAGBuild, outs() << "add ret node " << iter->second << "\n");
pag->addRetNode(
pag->addRetNode(iter->second,
llvmModuleSet()->getCallGraphNode(SVFUtil::cast<Function>(
llvmModuleSet()->getLLVMValue(iter->first))),
iter->second);
llvmModuleSet()->getLLVMValue(iter->first))));
}

for (SymbolTableInfo::FunToIDMapTy::iterator iter =
symTable->varargSyms().begin();
iter != symTable->varargSyms().end(); ++iter)
{
DBOUT(DPAGBuild, outs() << "add vararg node " << iter->second << "\n");
pag->addVarargNode(
pag->addVarargNode(iter->second,
llvmModuleSet()->getCallGraphNode(SVFUtil::cast<Function>(
llvmModuleSet()->getLLVMValue(iter->first))),
iter->second);
llvmModuleSet()->getLLVMValue(iter->first))));
}

/// add address edges for constant nodes.
Expand Down
2 changes: 1 addition & 1 deletion svf-llvm/lib/SVFIRExtAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
38 changes: 19 additions & 19 deletions svf/include/SVFIR/SVFIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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<s64_t, u64_t>& intValue, const NodeID i,
inline NodeID addConstantIntValNode(const SVFValue* curInst, NodeID i, const std::pair<s64_t, u64_t>& 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);
}

Expand Down Expand Up @@ -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<s64_t, u64_t>& intValue, const NodeID i)
inline NodeID addConstantIntObjNode(const SVFValue* curInst, NodeID i, const std::pair<s64_t, u64_t>& 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());
}

Expand Down Expand Up @@ -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);
}

Expand Down
24 changes: 12 additions & 12 deletions svf/include/SVFIR/SVFVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
}
Expand Down Expand Up @@ -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)
{
}
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions svf/lib/SVFIR/SVFIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
14 changes: 6 additions & 8 deletions svf/lib/SVFIR/SVFVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit a837b3f

Please sign in to comment.