10000 add arraySize to AddrStmt by bjjwwang · Pull Request #1324 · SVF-tools/SVF · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add arraySize to AddrStmt #1324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions svf-llvm/include/SVF-LLVM/SVFIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,56 @@ class SVFIRBuilder: public llvm::InstVisitor<SVFIRBuilder>
}
return nullptr;
}

/// Add Address edge from allocinst with arraysize like "%4 = alloca i8, i64 3"
inline AddrStmt* addAddrWithStackArraySz(NodeID src, NodeID dst, llvm::AllocaInst& inst) {
AddrStmt* edge = addAddrEdge(src, dst);
if (inst.getArraySize()) {
SVFValue* arrSz = LLVMModuleSet::getLLVMModuleSet()->getSVFValue(inst.getArraySize());
edge->addArrSize(arrSz);
}
return edge;
}

/// Add Address edge from ext call with args like "%5 = call i8* @malloc(i64 noundef 5)"
inline AddrStmt* addAddrWithHeapSz(NodeID src, NodeID dst, const CallBase* cs) {
// get name of called function
AddrStmt* edge = addAddrEdge(src, dst);

llvm::Function* calledFunc = cs->getCalledFunction();
std::string functionName;
if (calledFunc) {
functionName = calledFunc->getName().str();
}
else
{
SVFUtil::wrnMsg("not support indirect call to add AddrStmt.\n");
}
if (functionName == "malloc") {
if (cs->arg_size() > 0) {
const llvm::Value* val = cs->getArgOperand(0);
SVFValue* svfval = LLVMModuleSet::getLLVMModuleSet()->getSVFValue(val);
edge->addArrSize(svfval);
}
}
// Check if the function called is 'calloc' and process its arguments.
// e.g. "%5 = call i8* @calloc(1, 8)", edge should add two SVFValue (1 and 8)
else if (functionName == "calloc") {
if (cs->arg_size() > 1) {
edge->addArrSize(LLVMModuleSet::getLLVMModuleSet()->getSVFValue(cs->getArgOperand(0)));
edge->addArrSize(LLVMModuleSet::getLLVMModuleSet()->getSVFValue(cs->getArgOperand(1)));
}
}
else {
if (cs->arg_size() > 0) {
const llvm::Value* val = cs->getArgOperand(0);
SVFValue* svfval = LLVMModuleSet::getLLVMModuleSet()->getSVFValue(val);
edge->addArrSize(svfval);
}
}
return edge;
}

/// Add Copy edge
inline CopyStmt* addCopyEdge(NodeID src, NodeID dst)
{
Expand Down
2 changes: 1 addition & 1 deletion svf-llvm/lib/SVFIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ void SVFIRBuilder::visitAllocaInst(AllocaInst &inst)

NodeID src = getObjectNode(&inst);

addAddrEdge(src, dst);
addAddrWithStackArraySz(src, dst, inst);

}

Expand Down
4 changes: 2 additions & 2 deletions svf-llvm/lib/SVFIRExtAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void SVFIRBuilder::handleExtCall(const CallBase* cs, const SVFFunction* svfCalle
{
NodeID val = pag->getValueNode(svfInst);
NodeID obj = pag->getObjectNode(svfInst);
addAddrEdge(obj, val);
addAddrWithHeapSz(obj, val, cs);
}
else if (isHeapAllocExtCallViaArg(svfCall))
{
Expand All @@ -146,7 +146,7 @@ void SVFIRBuilder::handleExtCall(const CallBase* cs, const SVFFunction* svfCalle
NodeID obj = pag->addDummyObjNode(arg->getType());
if (vnArg && dummy && obj)
{
addAddrEdge(obj, dummy);
addAddrWithHeapSz(obj, dummy, cs);
addStoreEdge(dummy, vnArg);
}
}
Expand Down
11 changes: 11 additions & 0 deletions svf/include/SVFIR/SVFStatements.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ class AddrStmt: public AssignStmt
AddrStmt(const AddrStmt&); ///< place holder
void operator=(const AddrStmt&); ///< place holder

std::vector<SVFValue*> arrSize; ///< Array size of the allocated memory

public:
/// Methods for support type inquiry through isa, cast, and dyn_cast:
//@{
Expand All @@ -343,6 +345,15 @@ class AddrStmt: public AssignStmt

virtual const std::string toString() const override;

inline void addArrSize(SVFValue* size) { //TODO:addSizeVar
arrSize.push_back(size);
}

///< get array size of the allocated memory
inline const std::vector<SVFValue*>& getArrSize() const { //TODO:getSizeVars
return arrSize;
}

};

/*!
Expand Down
0