@@ -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 }
0 commit comments