Skip to content

Commit 4bf4806

Browse files
authored
add heap and stack obj var and fix CI (#1608)
* add heap and stack obj var * update comments * use base object var to distinguish heap object * use base object var to distinguish stack object * beautify class hierarchy * beautify class hierarchy * beautify class hierarchy * beautify class hierarchy
1 parent a1c2a90 commit 4bf4806

File tree

25 files changed

+472
-224
lines changed

25 files changed

+472
-224
lines changed

.github/workflows/github-action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
sudo apt-get update
4141
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
4242
sudo apt-get update
43-
sudo apt-get install cmake gcc g++ nodejs doxygen graphviz lcov libncurses5-dev libtinfo5 libzstd-dev
43+
sudo apt-get install cmake gcc g++ nodejs doxygen graphviz lcov libncurses5-dev libtinfo6 libzstd-dev
4444
4545
# build-svf
4646
- name: build-svf

.github/workflows/svf-lib_publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
sudo apt-get update
4141
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
4242
sudo apt-get update
43-
sudo apt-get install cmake gcc g++ nodejs doxygen graphviz libncurses5-dev libtinfo5 libzstd-dev
43+
sudo apt-get install cmake gcc g++ nodejs doxygen graphviz libncurses5-dev libtinfo6 libzstd-dev
4444
sudo apt-get update
4545
sudo apt-get install -y astyle
4646
- name: env-setup

svf-llvm/include/SVF-LLVM/LLVMUtil.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ inline bool isHeapAllocExtCall(const Instruction *inst)
360360
return isHeapAllocExtCallViaRet(inst) || isHeapAllocExtCallViaArg(inst);
361361
}
362362

363+
// Check if a given value represents a heap object.
364+
bool isHeapObj(const Value* val);
365+
363366
/// Whether an instruction is a callsite in the application code, excluding llvm intrinsic calls
364367
bool isNonInstricCallSite(const Instruction* inst);
365368

svf-llvm/lib/LLVMUtil.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,30 @@ bool LLVMUtil::isHeapAllocExtCallViaArg(const Instruction* inst)
646646
}
647647
}
648648

649+
/**
650+
* Check if a given value represents a heap object.
651+
*
652+
* @param val The value to check.
653+
* @return True if the value represents a heap object, false otherwise.
654+
*/
655+
bool LLVMUtil::isHeapObj(const Value* val)
656+
{
657+
// Check if the value is an argument in the program entry function
658+
if (ArgInProgEntryFunction(val))
659+
{
660+
// Return true if the value does not have a first use via cast instruction
661+
return !getFirstUseViaCastInst(val);
662+
}
663+
// Check if the value is an instruction and if it is a heap allocation external call
664+
else if (SVFUtil::isa<Instruction>(val) &&
665+
LLVMUtil::isHeapAllocExtCall(SVFUtil::cast<Instruction>(val)))
666+
{
667+
return true;
668+
}
669+
// Return false if none of the above conditions are met
670+
return false;
671+
}
672+
649673
bool LLVMUtil::isNonInstricCallSite(const Instruction* inst)
650674
{
651675
bool res = false;

svf-llvm/lib/SVFIRBuilder.cpp

Lines changed: 75 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -214,53 +214,88 @@ void SVFIRBuilder::initialiseNodes()
214214
pag->addBlackholePtrNode();
215215
addNullPtrNode();
216216

217-
for (SymbolTableInfo::ValueToIDMapTy::iterator iter =
218-
symTable->valSyms().begin(); iter != symTable->valSyms().end();
219-
++iter)
220-
{
221-
DBOUT(DPAGBuild, outs() << "add val node " << iter->second << "\n");
222-
if(iter->second == symTable->blkPtrSymID() || iter->second == symTable->nullPtrSymID())
223-
continue;
217+
// Iterate over all value symbols in the symbol table
218+
for (SymbolTableInfo::ValueToIDMapTy::iterator iter =
219+
symTable->valSyms().begin(); iter != symTable->valSyms().end();
220+
++iter)
221+
{
222+
// Debug output for adding value node
223+
DBOUT(DPAGBuild, outs() << "add val node " << iter->second << "\n");
224224

225-
const ICFGNode* icfgNode = nullptr;
226-
if (const Instruction* inst =
227-
SVFUtil::dyn_cast<Instruction>(llvmModuleSet()->getLLVMValue(iter->first)))
228-
{
229-
if (llvmModuleSet()->hasICFGNode(inst))
230-
{
231-
icfgNode = llvmModuleSet()->getICFGNode(inst);
232-
}
233-
}
225+
// Skip blackhole and null pointer symbols
226+
if(iter->second == symTable->blkPtrSymID() || iter->second == symTable->nullPtrSymID())
227+
continue;
234228

235-
if (const Function* func =
236-
SVFUtil::dyn_cast<Function>(llvmModuleSet()->getLLVMValue(iter->first)))
237-
{
238-
const CallGraphNode* cgn = llvmModuleSet()->getCallGraphNode(func);
239-
pag->addFunValNode(cgn, iter->second, icfgNode);
240-
}
241-
else
229+
const ICFGNode* icfgNode = nullptr;
230+
231+
// Check if the value is an instruction and get its ICFG node
232+
if (const Instruction* inst =
233+
SVFUtil::dyn_cast<Instruction>(llvmModuleSet()->getLLVMValue(iter->first)))
234+
{
235+
if (llvmModuleSet()->hasICFGNode(inst))
242236
{
243-
pag->addValNode(iter->first, iter->second, icfgNode);
237+
icfgNode = llvmModuleSet()->getICFGNode(inst);
244238
}
245239
}
246240

247-
for (SymbolTableInfo::ValueToIDMapTy::iterator iter =
248-
symTable->objSyms().begin(); iter != symTable->objSyms().end();
249-
++iter)
241+
// Check if the value is a function and get its call graph node
242+
if (const Function* func =
243+
SVFUtil::dyn_cast<Function>(llvmModuleSet()->getLLVMValue(iter->first)))
250244
{
251-
DBOUT(DPAGBuild, outs() << "add obj node " << iter->second << "\n");
252-
if(iter->second == symTable->blackholeSymID() || iter->second == symTable->constantSymID())
253-
continue;
254-
if (const Function* func = SVFUtil::dyn_cast<Function>(
255-
llvmModuleSet()->getLLVMValue(iter->first)))
256-
{
257-
pag->addFunObjNode(llvmModuleSet()->getCallGraphNode(func), iter->second);
258-
}
259-
else
260-
{
261-
pag->addObjNode(iter->first, iter->second);
262-
}
245+
const CallGraphNode* cgn = llvmModuleSet()->getCallGraphNode(func);
246+
// add value node representing the function
247+
pag->addFunValNode(cgn, iter->second, icfgNode);
248+
}
249+
else
250+
{
251+
// Add value node to PAG
252+
pag->addValNode(iter->first, iter->second, icfgNode);
263253
}
254+
}
255+
256+
// Iterate over all object symbols in the symbol table
257+
for (SymbolTableInfo::ValueToIDMapTy::iterator iter =
258+
symTable->objSyms().begin(); iter != symTable->objSyms().end();
259+
++iter)
260+
{
261+
// Debug output for adding object node
262+
DBOUT(DPAGBuild, outs() << "add obj node " << iter->second << "\n");
263+
264+
// Skip blackhole and constant symbols
265+
if(iter->second == symTable->blackholeSymID() || iter->second == symTable->constantSymID())
266+
continue;
267+
268+
// Get the LLVM value corresponding to the symbol
269+
const Value* llvmValue = llvmModuleSet()->getLLVMValue(iter->first);
270+
271+
// Check if the value is a function and add a function object node
272+
if (const Function* func = SVFUtil::dyn_cast<Function>(llvmValue))
273+
{
274+
pag->addFunObjNode(llvmModuleSet()->getCallGraphNode(func), iter->second);
275+
}
276+
// Check if the value is a heap object and add a heap object node
277+
else if (LLVMUtil::isHeapObj(llvmValue))
278+
{
279+
const SVFFunction* f =
280+
SVFUtil::cast<SVFInstruction>(iter->first)->getFunction();
281+
pag->addHeapObjNode(iter->first, f, iter->second);
282+
llvmModuleSet()->setValueAttr(llvmValue,pag->getGNode(iter->second));
283+
}
284+
// Check if the value is an alloca instruction and add a stack object node
285+
else if (SVFUtil::isa<AllocaInst>(llvmValue))
286+
{
287+
const SVFFunction* f =
288+
SVFUtil::cast<SVFInstruction>(iter->first)->getFunction();
289+
pag->addStackObjNode(iter->first, f, iter->second);
290+
llvmModuleSet()->setValueAttr(llvmValue,
291+
pag->getGNode(iter->second));
292+
}
293+
// Add a generic object node for other types of values
294+
else
295+
{
296+
pag->addObjNode(iter->first, iter->second);
297+
}
298+
}
264299

265300
for (SymbolTableInfo::FunToIDMapTy::iterator iter =
266301
symTable->retSyms().begin(); iter != symTable->retSyms().end();
@@ -1347,7 +1382,7 @@ void SVFIRBuilder::setCurrentBBAndValueForPAGEdge(PAGEdge* edge)
13471382
{
13481383
const SVFFunction* srcFun = edge->getSrcNode()->getFunction();
13491384
const SVFFunction* dstFun = edge->getDstNode()->getFunction();
1350-
if(srcFun!=nullptr && !SVFUtil::isa<RetPE>(edge) && !SVFUtil::isa<SVFFunction>(edge->getSrcNode()->getValue()))
1385+
if(srcFun!=nullptr && !SVFUtil::isa<RetPE>(edge) && edge->getSrcNode()->hasValue() && !SVFUtil::isa<SVFFunction>(edge->getSrcNode()->getValue()))
13511386
{
13521387
assert(srcFun==curInst->getFunction() && "SrcNode of the PAGEdge not in the same function?");
13531388
}

svf/include/DDA/DDAVFSolver.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,11 @@ class DDAVFSolver
471471
virtual inline bool isLocalCVarInRecursion(const CVar& var) const
472472
{
473473
NodeID id = getPtrNodeID(var);
474+
const BaseObjVar* baseObj = _pag->getBaseObject(id);
475+
assert(baseObj && "base object is null??");
474476
const MemObj* obj = _pag->getObject(id);
475477
assert(obj && "object not found!!");
476-
if(obj->isStack())
478+
if(SVFUtil::isa<StackObjVar>(baseObj))
477479
{
478480
if(const SVFFunction* svffun = _pag->getGNode(id)->getFunction())
479481
{
@@ -637,9 +639,8 @@ class DDAVFSolver
637639
//@{
638640
virtual inline bool isHeapCondMemObj(const CVar& var, const StoreSVFGNode*)
639641
{
640-
const MemObj* mem = _pag->getObject(getPtrNodeID(var));
641-
assert(mem && "memory object is null??");
642-
return mem->isHeap();
642+
const BaseObjVar* pVar = _pag->getBaseObject(getPtrNodeID(var));
643+
return pVar && SVFUtil::isa<HeapObjVar, DummyObjVar>(pVar);
643644
}
644645

645646
inline bool isArrayCondMemObj(const CVar& var) const

0 commit comments

Comments
 (0)