Static Value-Flow Analysis
MemRegion.cpp
Go to the documentation of this file.
1 //===- MemRegion.cpp -- Memory region-----------------------------------------//
2 //
3 // SVF: Static Value-Flow Analysis
4 //
5 // Copyright (C) <2013-2017> <Yulei Sui>
6 //
7 
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
17 
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 //
21 //===----------------------------------------------------------------------===//
22 
23 /*
24  * MemRegion.cpp
25  *
26  * Created on: Dec 14, 2013
27  * Author: Yulei Sui
28  */
29 
30 #include "Util/Options.h"
31 #include "SVFIR/SVFModule.h"
32 #include "MSSA/MemRegion.h"
33 #include "MSSA/MSSAMuChi.h"
34 
35 using namespace SVF;
36 using namespace SVFUtil;
37 
40 
42  pta(p), ptrOnlyMSSA(ptrOnly)
43 {
45  callGraphSCC = new SCC(callGraph);
46 }
47 
52 {
53 
54  for (MRSet::iterator it = memRegSet.begin(), eit = memRegSet.end();
55  it != eit; ++it)
56  {
57  delete *it;
58  }
59 
60  delete callGraphSCC;
61  callGraphSCC = nullptr;
62  callGraph = nullptr;
63  pta = nullptr;
64 }
65 
69 void MRGenerator::createMR(const SVFFunction* fun, const NodeBS& cpts)
70 {
71  const NodeBS& repCPts = getRepPointsTo(cpts);
72  MemRegion mr(repCPts);
73  MRSet::const_iterator mit = memRegSet.find(&mr);
74  if(mit!=memRegSet.end())
75  {
76  const MemRegion* mr = *mit;
77  MRSet& mrs = funToMRsMap[fun];
78  if(mrs.find(mr)==mrs.end())
79  mrs.insert(mr);
80  }
81  else
82  {
83  MemRegion* m = new MemRegion(repCPts);
84  memRegSet.insert(m);
85  funToMRsMap[fun].insert(m);
86  }
87 }
88 
92 const MemRegion* MRGenerator::getMR(const NodeBS& cpts) const
93 {
94  MemRegion mr(getRepPointsTo(cpts));
95  MRSet::iterator mit = memRegSet.find(&mr);
96  assert(mit!=memRegSet.end() && "memory region not found!!");
97  return *mit;
98 }
99 
100 
105 {
106  SVFIR* pag = pta->getPAG();
107  for (SVFIR::iterator nIter = pag->begin(); nIter != pag->end(); ++nIter)
108  {
109  if(ObjVar* obj = SVFUtil::dyn_cast<ObjVar>(nIter->second))
110  {
111  if (obj->getMemObj()->isGlobalObj())
112  {
113  allGlobals.set(nIter->first);
114  allGlobals |= CollectPtsChain(nIter->first);
115  }
116  }
117  }
118 }
119 
125 {
126 
127  DBOUT(DGENERAL, outs() << pasMsg("Generate Memory Regions \n"));
128 
129  collectGlobals();
130 
131  callGraphSCC->find();
132 
133  DBOUT(DGENERAL, outs() << pasMsg("\tCollect ModRef For Load/Store \n"));
134 
137 
138  DBOUT(DGENERAL, outs() << pasMsg("\tCollect ModRef For const CallICFGNode*\n"));
139 
142 
143  DBOUT(DGENERAL, outs() << pasMsg("\tPartition Memory Regions \n"));
145  partitionMRs();
147  updateAliasMRs();
148 }
149 
151 {
152  SVFIR* pag = pta->getPAG();
153  if (ptrOnlyMSSA)
154  return pag->hasPTASVFStmtList(node);
155  else
156  return pag->hasSVFStmtList(node);
157 }
158 
159 
161 {
162  SVFIR* pag = pta->getPAG();
163  if (ptrOnlyMSSA)
164  return pag->getPTASVFStmtList(node);
165  else
166  return pag->getSVFStmtList(node);
167 }
168 
169 
174 {
175 
176  PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph();
177  for (const auto& item: *svfirCallGraph)
178  {
179  const SVFFunction& fun = *item.second->getFunction();
180 
183  continue;
184 
185  for (SVFFunction::const_iterator iter = fun.begin(), eiter = fun.end();
186  iter != eiter; ++iter)
187  {
188  const SVFBasicBlock* bb = *iter;
189  for (const auto& inst: bb->getICFGNodeList())
190  {
191  SVFStmtList& pagEdgeList = getPAGEdgesFromInst(inst);
192  for (SVFStmtList::iterator bit = pagEdgeList.begin(), ebit =
193  pagEdgeList.end(); bit != ebit; ++bit)
194  {
195  const PAGEdge* inst = *bit;
196  pagEdgeToFunMap[inst] = &fun;
197  if (const StoreStmt *st = SVFUtil::dyn_cast<StoreStmt>(inst))
198  {
199  NodeBS cpts(pta->getPts(st->getLHSVarID()).toNodeBS());
200  // TODO: change this assertion check later when we have conditional points-to set
201  if (cpts.empty())
202  continue;
203  assert(!cpts.empty() && "null pointer!!");
204  addCPtsToStore(cpts, st, &fun);
205  }
206 
207  else if (const LoadStmt *ld = SVFUtil::dyn_cast<LoadStmt>(inst))
208  {
209  NodeBS cpts(pta->getPts(ld->getRHSVarID()).toNodeBS());
210  // TODO: change this assertion check later when we have conditional points-to set
211  if (cpts.empty())
212  continue;
213  assert(!cpts.empty() && "null pointer!!");
214  addCPtsToLoad(cpts, ld, &fun);
215  }
216  }
217  }
218  }
219  }
220 }
221 
222 
227 {
228 
229  DBOUT(DGENERAL, outs() << pasMsg("\t\tCollect Callsite PointsTo \n"));
230 
232  for(SVFIR::CallSiteSet::const_iterator it = pta->getPAG()->getCallSiteSet().begin(),
233  eit = pta->getPAG()->getCallSiteSet().end(); it!=eit; ++it)
234  {
235  collectCallSitePts((*it));
236  }
237 
238  DBOUT(DGENERAL, outs() << pasMsg("\t\tPerform Callsite Mod-Ref \n"));
239 
240  WorkList worklist;
241  getCallGraphSCCRevTopoOrder(worklist);
242 
243  while(!worklist.empty())
244  {
245  NodeID callGraphNodeID = worklist.pop();
247  const NodeBS& subNodes = callGraphSCC->subNodes(callGraphNodeID);
248  for(NodeBS::iterator it = subNodes.begin(), eit = subNodes.end(); it!=eit; ++it)
249  {
250  PTACallGraphNode* subCallGraphNode = callGraph->getCallGraphNode(*it);
252  modRefAnalysis(subCallGraphNode,worklist);
253  }
254  }
255 
256  DBOUT(DGENERAL, outs() << pasMsg("\t\tAdd PointsTo to Callsites \n"));
257 
258  for (const CallICFGNode* callBlockNode : pta->getPAG()->getCallSiteSet())
259  {
260  if(hasRefSideEffectOfCallSite(callBlockNode))
261  {
262  NodeBS refs = getRefSideEffectOfCallSite(callBlockNode);
263  addCPtsToCallSiteRefs(refs,callBlockNode);
264  }
265  if(hasModSideEffectOfCallSite(callBlockNode))
266  {
267  NodeBS mods = getModSideEffectOfCallSite(callBlockNode);
269  addCPtsToCallSiteMods(mods,callBlockNode);
270  addCPtsToCallSiteRefs(mods,callBlockNode);
271  }
272  }
273 }
274 
282 {
283 
284  if(cptsToRepCPtsMap.find(cpts)!=cptsToRepCPtsMap.end())
285  return;
286 
287  PointsToList subSetList;
288  NodeBS repCPts = cpts;
289  for(PtsToRepPtsSetMap::iterator it = cptsToRepCPtsMap.begin(),
290  eit = cptsToRepCPtsMap.end(); it!=eit; ++it)
291  {
292  NodeBS& existCPts = it->second;
293  if(cpts.contains(existCPts))
294  {
295  subSetList.insert(it->first);
296  }
297  else if(existCPts.contains(cpts))
298  {
299  repCPts = existCPts;
300  }
301  }
302 
303  for(PointsToList::iterator it = subSetList.begin(), eit = subSetList.end(); it!=eit; ++it)
304  {
305  cptsToRepCPtsMap[*it] = cpts;
306  }
307 
308  cptsToRepCPtsMap[cpts] = repCPts;
309 }
310 
315 {
316 
321  for(FunToPointsTosMap::iterator it = getFunToPointsToList().begin(), eit = getFunToPointsToList().end();
322  it!=eit; ++it)
323  {
324  for(PointsToList::iterator cit = it->second.begin(), ecit = it->second.end(); cit!=ecit; ++cit)
325  {
326  sortPointsTo(*cit);
327  }
328  }
330  for(FunToPointsTosMap::iterator it = getFunToPointsToList().begin(), eit = getFunToPointsToList().end();
331  it!=eit; ++it)
332  {
333  const SVFFunction* fun = it->first;
334  for(PointsToList::iterator cit = it->second.begin(), ecit = it->second.end(); cit!=ecit; ++cit)
335  {
336  createMR(fun,*cit);
337  }
338  }
339 
340 }
341 
346 {
347 
349  for(StoresToPointsToMap::const_iterator it = storesToPointsToMap.begin(), eit = storesToPointsToMap.end(); it!=eit; ++it)
350  {
351  MRSet aliasMRs;
352  const SVFFunction* fun = getFunction(it->first);
353  const NodeBS& storeCPts = it->second;
354  getAliasMemRegions(aliasMRs,storeCPts,fun);
355  for(MRSet::iterator ait = aliasMRs.begin(), eait = aliasMRs.end(); ait!=eait; ++ait)
356  {
357  storesToMRsMap[it->first].insert(*ait);
358  }
359  }
360 
361  for(LoadsToPointsToMap::const_iterator it = loadsToPointsToMap.begin(), eit = loadsToPointsToMap.end(); it!=eit; ++it)
362  {
363  MRSet aliasMRs;
364  const SVFFunction* fun = getFunction(it->first);
365  const NodeBS& loadCPts = it->second;
366  getMRsForLoad(aliasMRs, loadCPts, fun);
367  for(MRSet::iterator ait = aliasMRs.begin(), eait = aliasMRs.end(); ait!=eait; ++ait)
368  {
369  loadsToMRsMap[it->first].insert(*ait);
370  }
371  }
372 
374  for(CallSiteToPointsToMap::const_iterator it = callsiteToModPointsToMap.begin(),
375  eit = callsiteToModPointsToMap.end(); it!=eit; ++it)
376  {
377  const SVFFunction* fun = it->first->getCaller();
378  MRSet aliasMRs;
379  const NodeBS& callsiteModCPts = it->second;
380  getAliasMemRegions(aliasMRs,callsiteModCPts,fun);
381  for(MRSet::iterator ait = aliasMRs.begin(), eait = aliasMRs.end(); ait!=eait; ++ait)
382  {
383  callsiteToModMRsMap[it->first].insert(*ait);
384  }
385  }
386  for(CallSiteToPointsToMap::const_iterator it = callsiteToRefPointsToMap.begin(),
387  eit = callsiteToRefPointsToMap.end(); it!=eit; ++it)
388  {
389  const SVFFunction* fun = it->first->getCaller();
390  MRSet aliasMRs;
391  const NodeBS& callsiteRefCPts = it->second;
392  getMRsForCallSiteRef(aliasMRs, callsiteRefCPts, fun);
393  for(MRSet::iterator ait = aliasMRs.begin(), eait = aliasMRs.end(); ait!=eait; ++ait)
394  {
395  callsiteToRefMRsMap[it->first].insert(*ait);
396  }
397  }
398 }
399 
400 
405 {
406  for(NodeBS::iterator it = refs.begin(), eit = refs.end(); it!=eit; ++it)
407  {
408  if(isNonLocalObject(*it,fun))
409  funToRefsMap[fun].set(*it);
410  }
411 }
412 
417 {
418  for(NodeBS::iterator it = mods.begin(), eit = mods.end(); it!=eit; ++it)
419  {
420  if(isNonLocalObject(*it,fun))
421  funToModsMap[fun].set(*it);
422  }
423 }
424 
429 {
430  if(!refs.empty())
431  {
432  NodeBS refset = refs;
433  refset &= getCallSiteArgsPts(cs);
434  getEscapObjviaGlobals(refset,refs);
436  return csToRefsMap[cs] |= refset;
437  }
438  return false;
439 }
440 
445 {
446  if(!mods.empty())
447  {
448  NodeBS modset = mods;
449  modset &= (getCallSiteArgsPts(cs) | getCallSiteRetPts(cs));
450  getEscapObjviaGlobals(modset,mods);
452  return csToModsMap[cs] |= modset;
453  }
454  return false;
455 }
456 
457 
462 {
463 
464  NodeStack& topoOrder = callGraphSCC->topoNodeStack();
465  while(!topoOrder.empty())
466  {
467  NodeID callgraphNodeID = topoOrder.top();
468  topoOrder.pop();
469  worklist.push(callgraphNodeID);
470  }
471 }
472 
477 {
479  NodeBS& argsPts = csToCallSiteArgsPtsMap[cs];
480  SVFIR* pag = pta->getPAG();
481  CallICFGNode* callBlockNode = const_cast<CallICFGNode*>(cs);
482  const RetICFGNode* retBlockNode = cs->getRetICFGNode();
483 
484  WorkList worklist;
485  if (pag->hasCallSiteArgsMap(callBlockNode))
486  {
487  const SVFIR::SVFVarList& args = pta->getPAG()->getCallSiteArgsList(callBlockNode);
488  for(SVFIR::SVFVarList::const_iterator itA = args.begin(), ieA = args.end(); itA!=ieA; ++itA)
489  {
490  const PAGNode* node = *itA;
491  if(node->isPointer())
492  worklist.push(node->getId());
493  }
494  }
495 
496  while(!worklist.empty())
497  {
498  NodeID nodeId = worklist.pop();
499  const NodeBS& tmp = pta->getPts(nodeId).toNodeBS();
500  for(NodeBS::iterator it = tmp.begin(), eit = tmp.end(); it!=eit; ++it)
501  argsPts |= CollectPtsChain(*it);
502  }
503 
505  NodeBS& retPts = csToCallSiteRetPtsMap[cs];
506 
507  if (pta->getPAG()->callsiteHasRet(retBlockNode))
508  {
509  const PAGNode* node = pta->getPAG()->getCallSiteRet(retBlockNode);
510  if(node->isPointer())
511  {
512  const NodeBS& tmp = pta->getPts(node->getId()).toNodeBS();
513  for(NodeBS::iterator it = tmp.begin(), eit = tmp.end(); it!=eit; ++it)
514  retPts |= CollectPtsChain(*it);
515  }
516  }
517 
518 }
519 
520 
525 {
526  NodeID baseId = pta->getPAG()->getBaseObjVar(id);
527  NodeToPTSSMap::iterator it = cachedPtsChainMap.find(baseId);
528  if(it!=cachedPtsChainMap.end())
529  return it->second;
530  else
531  {
532  NodeBS& pts = cachedPtsChainMap[baseId];
533  pts |= pta->getPAG()->getFieldsAfterCollapse(baseId);
534 
535  WorkList worklist;
536  for(NodeBS::iterator it = pts.begin(), eit = pts.end(); it!=eit; ++it)
537  worklist.push(*it);
538 
539  while(!worklist.empty())
540  {
541  NodeID nodeId = worklist.pop();
542  const NodeBS& tmp = pta->getPts(nodeId).toNodeBS();
543  for(NodeBS::iterator it = tmp.begin(), eit = tmp.end(); it!=eit; ++it)
544  {
545  pts |= CollectPtsChain(*it);
546  }
547  }
548  return pts;
549  }
550 
551 }
552 
558 void MRGenerator::getEscapObjviaGlobals(NodeBS& globs, const NodeBS& calleeModRef)
559 {
560  for(NodeBS::iterator it = calleeModRef.begin(), eit = calleeModRef.end(); it!=eit; ++it)
561  {
562  const MemObj* obj = pta->getPAG()->getObject(*it);
563  (void)obj; // Suppress warning of unused variable under release build
564  assert(obj && "object not found!!");
565  if(allGlobals.test(*it))
566  globs.set(*it);
567  }
568 }
569 
574 bool MRGenerator::isNonLocalObject(NodeID id, const SVFFunction* curFun) const
575 {
576  const MemObj* obj = pta->getPAG()->getObject(id);
577  assert(obj && "object not found!!");
579  if(obj->isGlobalObj() || obj->isHeap())
580  return true;
583  else if(obj->isStack())
584  {
585  if(const SVFFunction* svffun = pta->getPAG()->getGNode(id)->getFunction())
586  {
587  if(svffun!=curFun)
588  return true;
589  else
591  }
592  }
593 
594  return false;
595 }
596 
600 bool MRGenerator::handleCallsiteModRef(NodeBS& mod, NodeBS& ref, const CallICFGNode* cs, const SVFFunction* callee)
601 {
603  if(isHeapAllocExtCall(cs))
604  {
605  SVFStmtList& pagEdgeList = getPAGEdgesFromInst(cs);
606  for (SVFStmtList::const_iterator bit = pagEdgeList.begin(),
607  ebit = pagEdgeList.end(); bit != ebit; ++bit)
608  {
609  const PAGEdge* edge = *bit;
610  if (const AddrStmt* addr = SVFUtil::dyn_cast<AddrStmt>(edge))
611  mod.set(addr->getRHSVarID());
612  }
613  }
615  else
616  {
617  mod = getModSideEffectOfFunction(callee);
618  ref = getRefSideEffectOfFunction(callee);
619  }
620  // add ref set
621  bool refchanged = addRefSideEffectOfCallSite(cs, ref);
622  // add mod set
623  bool modchanged = addModSideEffectOfCallSite(cs, mod);
624 
625  return refchanged || modchanged;
626 }
627 
633 {
634 
636  for(PTACallGraphNode::iterator it = callGraphNode->InEdgeBegin(), eit = callGraphNode->InEdgeEnd();
637  it!=eit; ++it)
638  {
639  PTACallGraphEdge* edge = *it;
640 
642  for(PTACallGraphEdge::CallInstSet::iterator cit = edge->getDirectCalls().begin(),
643  ecit = edge->getDirectCalls().end(); cit!=ecit; ++cit)
644  {
645  NodeBS mod, ref;
646  const CallICFGNode* cs = (*cit);
647  bool modrefchanged = handleCallsiteModRef(mod, ref, cs, callGraphNode->getFunction());
648  if(modrefchanged)
649  worklist.push(edge->getSrcID());
650  }
652  for(PTACallGraphEdge::CallInstSet::iterator cit = edge->getIndirectCalls().begin(),
653  ecit = edge->getIndirectCalls().end(); cit!=ecit; ++cit)
654  {
655  NodeBS mod, ref;
656  const CallICFGNode* cs = (*cit);
657  bool modrefchanged = handleCallsiteModRef(mod, ref, cs, callGraphNode->getFunction());
658  if(modrefchanged)
659  worklist.push(edge->getSrcID());
660  }
661  }
662 }
663 
668 {
669  if (isExtCall(cs) && !isHeapAllocExtCall(cs))
670  {
671  SVFStmtList& pagEdgeList = getPAGEdgesFromInst(cs);
672  NodeBS mods;
673  for (SVFStmtList::const_iterator bit = pagEdgeList.begin(), ebit =
674  pagEdgeList.end(); bit != ebit; ++bit)
675  {
676  const PAGEdge* edge = *bit;
677  if (const StoreStmt* st = SVFUtil::dyn_cast<StoreStmt>(edge))
678  mods |= pta->getPts(st->getLHSVarID()).toNodeBS();
679  }
680  return mods;
681  }
682  else
683  {
684  return getModSideEffectOfCallSite(cs);
685  }
686 }
687 
692 {
693  if (isExtCall(cs) && !isHeapAllocExtCall(cs))
694  {
695  SVFStmtList& pagEdgeList = getPAGEdgesFromInst(cs);
696  NodeBS refs;
697  for (SVFStmtList::const_iterator bit = pagEdgeList.begin(), ebit =
698  pagEdgeList.end(); bit != ebit; ++bit)
699  {
700  const PAGEdge* edge = *bit;
701  if (const LoadStmt* ld = SVFUtil::dyn_cast<LoadStmt>(edge))
702  refs |= pta->getPts(ld->getRHSVarID()).toNodeBS();
703  }
704  return refs;
705  }
706  else
707  {
708  return getRefSideEffectOfCallSite(cs);
709  }
710 }
711 
717 {
718  bool ref = !getRefInfoForCall(cs).empty();
719  bool mod = !getModInfoForCall(cs).empty();
720 
721  if (mod && ref)
722  return ModRefInfo::ModRef;
723  else if (ref)
724  return ModRefInfo::Ref;
725  else if (mod)
726  return ModRefInfo::Mod;
727  else
728  return ModRefInfo::NoModRef;
729 }
730 
736 {
737  bool ref = false;
738  bool mod = false;
739 
740  if (pta->getPAG()->hasValueNode(V))
741  {
742  const NodeBS pts(pta->getPts(pta->getPAG()->getValueNode(V)).toNodeBS());
743  const NodeBS csRef = getRefInfoForCall(cs);
744  const NodeBS csMod = getModInfoForCall(cs);
745  NodeBS ptsExpanded, csRefExpanded, csModExpanded;
746  pta->expandFIObjs(pts, ptsExpanded);
747  pta->expandFIObjs(csRef, csRefExpanded);
748  pta->expandFIObjs(csMod, csModExpanded);
749 
750  if (csRefExpanded.intersects(ptsExpanded))
751  ref = true;
752  if (csModExpanded.intersects(ptsExpanded))
753  mod = true;
754  }
755 
756  if (mod && ref)
757  return ModRefInfo::ModRef;
758  else if (ref)
759  return ModRefInfo::Ref;
760  else if (mod)
761  return ModRefInfo::Mod;
762  else
763  return ModRefInfo::NoModRef;
764 }
765 
770 {
771  bool ref = false;
772  bool mod = false;
773 
776  return ModRefInfo::NoModRef;
777 
778  const NodeBS cs1Ref = getRefInfoForCall(cs1);
779  const NodeBS cs1Mod = getModInfoForCall(cs1);
780  const NodeBS cs2Ref = getRefInfoForCall(cs2);
781  const NodeBS cs2Mod = getModInfoForCall(cs2);
782  NodeBS cs1RefExpanded, cs1ModExpanded, cs2RefExpanded, cs2ModExpanded;
783  pta->expandFIObjs(cs1Ref, cs1RefExpanded);
784  pta->expandFIObjs(cs1Mod, cs1ModExpanded);
785  pta->expandFIObjs(cs2Ref, cs2RefExpanded);
786  pta->expandFIObjs(cs2Mod, cs2ModExpanded);
787 
789  if (cs1RefExpanded.intersects(cs2ModExpanded))
790  ref = true;
792  if (cs1ModExpanded.intersects(cs2RefExpanded) || cs1ModExpanded.intersects(cs2ModExpanded))
793  mod = true;
795  if (cs1RefExpanded.intersects(cs2ModExpanded) && cs1ModExpanded.intersects(cs2ModExpanded))
796  ref = mod = true;
797 
798  if (ref && mod)
799  return ModRefInfo::ModRef;
800  else if (ref)
801  return ModRefInfo::Ref;
802  else if (mod)
803  return ModRefInfo::Mod;
804  else
805  return ModRefInfo::NoModRef;
806 }
807 
808 std::ostream& SVF::operator<<(std::ostream &o, const MRVer& mrver)
809 {
810  o << "MRVERID: " << mrver.getID() <<" MemRegion: " << mrver.getMR()->dumpStr() << " MRVERSION: " << mrver.getSSAVersion() << " MSSADef: " << mrver.getDef()->getType() << ", "
811  << mrver.getDef()->getMR()->dumpStr() ;
812  return o;
813 }
unsigned u32_t
Definition: CommandLine.h:18
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition: SVFType.h:484
#define DGENERAL
Definition: SVFType.h:490
cJSON * p
Definition: cJSON.cpp:2559
cJSON * item
Definition: cJSON.h:222
virtual void expandFIObjs(const PointsTo &pts, PointsTo &expandedPts)
Expand FI objects.
const PointsTo & getPts(NodeID id) override
const SVFFunction * getCaller() const
Return callsite.
Definition: ICFGNode.h:470
const RetICFGNode * getRetICFGNode() const
Return callsite.
Definition: ICFGNode.h:457
bool push(const Data &data)
Definition: WorkList.h:165
bool empty() const
Definition: WorkList.h:146
NodeID getSrcID() const
get methods of the components
Definition: GenericGraph.h:81
iterator begin()
Iterators.
Definition: GenericGraph.h:627
NodeType * getGNode(NodeID id) const
Get a node.
Definition: GenericGraph.h:653
IDToNodeMapTy::iterator iterator
Node Iterators.
Definition: GenericGraph.h:606
iterator InEdgeBegin()
Definition: GenericGraph.h:462
iterator InEdgeEnd()
Definition: GenericGraph.h:466
bool hasValueNode(const SVFValue *V)
Definition: IRGraph.h:141
NodeID getValueNode(const SVFValue *V)
Definition: IRGraph.h:137
virtual void getMRsForCallSiteRef(MRSet &aliasMRs, const NodeBS &cpts, const SVFFunction *)
Get memory regions for call site ref according to cpts.
Definition: MemRegion.h:326
PTACallGraph * callGraph
Definition: MemRegion.h:199
LoadsToMRsMap loadsToMRsMap
Map a load SVFIR Edge to its memory regions sets in order for inserting mus in Memory SSA.
Definition: MemRegion.h:205
NodeToPTSSMap cachedPtsChainMap
Map a pointer to its cached points-to chain;.
Definition: MemRegion.h:240
FunToPointsTosMap & getFunToPointsToList()
Definition: MemRegion.h:371
const NodeBS & getModSideEffectOfCallSite(const CallICFGNode *cs)
Get indirect mods of a callsite.
Definition: MemRegion.h:403
bool hasModSideEffectOfCallSite(const CallICFGNode *cs)
Has indirect mods of a callsite.
Definition: MemRegion.h:413
virtual void collectModRefForLoadStore()
Generate regions for loads/stores.
Definition: MemRegion.cpp:173
CallSiteToPointsToMap csToCallSiteRetPtsMap
Map a callsite to all its object might return from its callees.
Definition: MemRegion.h:237
StoresToMRsMap storesToMRsMap
Map a store SVFIR Edge to its memory regions sets in order for inserting chis in Memory SSA.
Definition: MemRegion.h:207
SVFStmtList & getPAGEdgesFromInst(const ICFGNode *node)
Given an instruction, get all its the PAGEdge (statement) in sequence.
Definition: MemRegion.cpp:160
FunToPointsToMap funToModsMap
Map a function to its indirect defs of memory objects.
Definition: MemRegion.h:229
bool isNonLocalObject(NodeID id, const SVFFunction *curFun) const
Definition: MemRegion.cpp:574
const SVFFunction * getFunction(const PAGEdge *pagEdge) const
Get the function which SVFIR Edge located.
Definition: MemRegion.h:435
CallSiteToPointsToMap callsiteToRefPointsToMap
Map a callsite to it refs cpts set.
Definition: MemRegion.h:217
void addModSideEffectOfFunction(const SVFFunction *fun, const NodeBS &mods)
Add indirect def an memory object in the function.
Definition: MemRegion.cpp:416
FunToMRsMap funToMRsMap
Map a function to all its memory regions.
Definition: MemRegion.h:203
virtual void generateMRs()
Start generating memory regions.
Definition: MemRegion.cpp:124
virtual void collectModRefForCall()
Generate regions for calls/rets.
Definition: MemRegion.cpp:226
const MemRegion * getMR(const NodeBS &cpts) const
Get a memory region according to cpts.
Definition: MemRegion.cpp:92
CallSiteToPointsToMap csToModsMap
Map a callsite to its indirect defs of memory objects.
Definition: MemRegion.h:233
const NodeBS & getRefSideEffectOfCallSite(const CallICFGNode *cs)
Get indirect refs of a callsite.
Definition: MemRegion.h:398
virtual void sortPointsTo(const NodeBS &cpts)
Given a condition pts, insert into cptsToRepCPtsMap for region generation.
Definition: MemRegion.cpp:281
void addCPtsToLoad(NodeBS &cpts, const LoadStmt *ld, const SVFFunction *fun)
Definition: MemRegion.h:347
CallSiteToMRsMap callsiteToRefMRsMap
Map a callsite to its refs regions.
Definition: MemRegion.h:209
const NodeBS & getModSideEffectOfFunction(const SVFFunction *fun)
Get indirect mods of a function.
Definition: MemRegion.h:393
StoresToPointsToMap storesToPointsToMap
Map a store SVFIR Edge to its CPts set map.
Definition: MemRegion.h:215
NodeBS & CollectPtsChain(NodeID id)
Definition: MemRegion.cpp:524
bool addRefSideEffectOfCallSite(const CallICFGNode *cs, const NodeBS &refs)
Add indirect uses an memory object in the function.
Definition: MemRegion.cpp:428
SVFIR::SVFStmtList SVFStmtList
SVFIR edge list.
Definition: MemRegion.h:176
void addRefSideEffectOfFunction(const SVFFunction *fun, const NodeBS &refs)
Add/Get methods for side-effect of functions and callsites.
Definition: MemRegion.cpp:404
OrderedSet< NodeBS, SVFUtil::equalNodeBS > PointsToList
Definition: MemRegion.h:143
bool addModSideEffectOfCallSite(const CallICFGNode *cs, const NodeBS &mods)
Add indirect def an memory object in the function.
Definition: MemRegion.cpp:444
void addCPtsToCallSiteRefs(NodeBS &cpts, const CallICFGNode *cs)
Definition: MemRegion.h:353
NodeBS getRefInfoForCall(const CallICFGNode *cs)
Definition: MemRegion.cpp:691
bool hasRefSideEffectOfCallSite(const CallICFGNode *cs)
Has indirect refs of a callsite.
Definition: MemRegion.h:408
OrderedSet< const MemRegion *, MemRegion::equalMemRegion > MRSet
Get typedef from Pointer Analysis.
Definition: MemRegion.h:141
const NodeBS & getRepPointsTo(const NodeBS &cpts) const
Get superset cpts set.
Definition: MemRegion.h:186
virtual void updateAliasMRs()
Update aliased regions for loads/stores/callsites.
Definition: MemRegion.cpp:345
void collectCallSitePts(const CallICFGNode *cs)
Definition: MemRegion.cpp:476
SCC * callGraphSCC
Definition: MemRegion.h:198
bool hasSVFStmtList(const ICFGNode *icfgNode)
Whether this instruction has SVFIR Edge.
Definition: MemRegion.cpp:150
NodeBS & getCallSiteRetPts(const CallICFGNode *cs)
Return the pts chain of the return parameter of the callsite.
Definition: MemRegion.h:260
PAGEdgeToFunMap pagEdgeToFunMap
Map a PAGEdge to its fun.
Definition: MemRegion.h:224
void getCallGraphSCCRevTopoOrder(WorkList &worklist)
Get reverse topo call graph scc.
Definition: MemRegion.cpp:461
PtsToRepPtsSetMap cptsToRepCPtsMap
Map a condition pts to its rep conditional pts (super set points-to)
Definition: MemRegion.h:280
void addCPtsToCallSiteMods(NodeBS &cpts, const CallICFGNode *cs)
Definition: MemRegion.h:358
CallSiteToPointsToMap callsiteToModPointsToMap
Map a callsite to it mods cpts set.
Definition: MemRegion.h:219
virtual void getMRsForLoad(MRSet &aliasMRs, const NodeBS &cpts, const SVFFunction *)
Get memory regions for a load statement according to cpts.
Definition: MemRegion.h:319
const NodeBS & getRefSideEffectOfFunction(const SVFFunction *fun)
Get indirect refs of a function.
Definition: MemRegion.h:388
virtual void partitionMRs()
Partition regions.
Definition: MemRegion.cpp:314
ModRefInfo getModRefInfo(const CallICFGNode *cs)
Definition: MemRegion.cpp:716
void createMR(const SVFFunction *fun, const NodeBS &cpts)
Generate a memory region and put in into functions which use it.
Definition: MemRegion.cpp:69
void destroy()
Clean up memory.
Definition: MemRegion.cpp:51
CallSiteToPointsToMap csToRefsMap
Map a callsite to its indirect uses of memory objects.
Definition: MemRegion.h:231
MRGenerator(BVDataPTAImpl *p, bool ptrOnly)
Definition: MemRegion.cpp:41
virtual bool handleCallsiteModRef(NodeBS &mod, NodeBS &ref, const CallICFGNode *cs, const SVFFunction *fun)
Get Mod-Ref of a callee function.
Definition: MemRegion.cpp:600
NodeBS & getCallSiteArgsPts(const CallICFGNode *cs)
Return the pts chain of all callsite arguments.
Definition: MemRegion.h:255
virtual void getAliasMemRegions(MRSet &aliasMRs, const NodeBS &cpts, const SVFFunction *fun)
Get all aliased mem regions from function fun according to cpts.
Definition: MemRegion.h:309
virtual void modRefAnalysis(PTACallGraphNode *callGraphNode, WorkList &worklist)
Mod-Ref analysis for callsite invoking this callGraphNode.
Definition: MemRegion.cpp:632
void getEscapObjviaGlobals(NodeBS &globs, const NodeBS &pts)
Get all the objects in callee's modref escaped via global objects (the chain pts of globals)
Definition: MemRegion.cpp:558
CallSiteToMRsMap callsiteToModMRsMap
Map a callsite to its mods regions.
Definition: MemRegion.h:211
NodeBS getModInfoForCall(const CallICFGNode *cs)
getModRefInfo APIs
Definition: MemRegion.cpp:667
NodeBS allGlobals
All global variable SVFIR node ids.
Definition: MemRegion.h:243
LoadsToPointsToMap loadsToPointsToMap
Map a load SVFIR Edge to its CPts set map.
Definition: MemRegion.h:213
void addCPtsToStore(NodeBS &cpts, const StoreStmt *st, const SVFFunction *fun)
Add cpts to store/load.
Definition: MemRegion.h:341
FunToPointsToMap funToRefsMap
Map a function to its indirect uses of memory objects.
Definition: MemRegion.h:227
SCCDetection< PTACallGraph * > SCC
Call Graph SCC.
Definition: MemRegion.h:178
MRSet memRegSet
A set of All memory regions.
Definition: MemRegion.h:278
BVDataPTAImpl * pta
Definition: MemRegion.h:197
void collectGlobals()
Collect all global variables for later escape analysis.
Definition: MemRegion.cpp:104
CallSiteToPointsToMap csToCallSiteArgsPtsMap
Map a callsite to all its object might pass into its callees.
Definition: MemRegion.h:235
MRVERSION getSSAVersion() const
Return SSA version.
Definition: MSSAMuChi.h:69
MRVERID getID() const
Get MRVERID.
Definition: MSSAMuChi.h:81
MSSADef * getDef() const
Get MSSADef.
Definition: MSSAMuChi.h:75
const MemRegion * getMR() const
Return the memory region.
Definition: MSSAMuChi.h:63
static u32_t totalVERNum
ver ID 0 is reserved
Definition: MSSAMuChi.h:50
DEFTYPE getType() const
Return type of this CHI.
Definition: MSSAMuChi.h:360
const MemRegion * getMR() const
Return memory region.
Definition: MSSAMuChi.h:354
bool isGlobalObj() const
bool isHeap() const
bool isStack() const
Memory Region class.
Definition: MemRegion.h:56
static u32_t totalMRNum
region ID 0 is reserved
Definition: MemRegion.h:62
std::string dumpStr() const
Dump string.
Definition: MemRegion.h:93
static const Option< bool > IgnoreDeadFun
Definition: Options.h:139
CallInstSet & getIndirectCalls()
Definition: PTACallGraph.h:99
CallInstSet & getDirectCalls()
Definition: PTACallGraph.h:95
PTACallGraphEdge::CallGraphEdgeSet::iterator iterator
Definition: PTACallGraph.h:179
const SVFFunction * getFunction() const
Get function of this call node.
Definition: PTACallGraph.h:198
PTACallGraphNode * getCallGraphNode(NodeID id) const
Get call graph node.
Definition: PTACallGraph.h:339
SVFIR * getPAG() const
PTACallGraph * getCallGraph() const
Return call graph.
NodeBS toNodeBS() const
Returns this points-to set as a NodeBS.
Definition: PointsTo.cpp:313
void find(void)
Definition: SCC.h:308
bool isInCycle(NodeID n) const
whether the node is in a cycle
Definition: SCC.h:149
GNodeStack & topoNodeStack()
Definition: SCC.h:128
const NodeBS & subNodes(NodeID n) const
get all subnodes in one scc, if size is empty insert itself into the set
Definition: SCC.h:173
NodeID getId() const
Get ID.
Definition: GenericGraph.h:260
const std::vector< const ICFGNode * > & getICFGNodeList() const
Definition: SVFValue.h:569
const_iterator end() const
Definition: SVFValue.h:440
const_iterator begin() const
Definition: SVFValue.h:435
bool isUncalledFunction() const
Definition: SVFValue.h:455
std::vector< const SVFBasicBlock * >::const_iterator const_iterator
Definition: SVFValue.h:305
bool hasPTASVFStmtList(const ICFGNode *inst) const
Definition: SVFIR.h:215
PTACallGraph * getCallGraph()
Definition: SVFIR.h:192
const SVFVarList & getCallSiteArgsList(const CallICFGNode *cs) const
Get callsite argument list.
Definition: SVFIR.h:292
const MemObj * getObject(NodeID id) const
Definition: SVFIR.h:395
const SVFVar * getCallSiteRet(const RetICFGNode *cs) const
Get callsite return.
Definition: SVFIR.h:304
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition: SVFIR.h:115
NodeBS getFieldsAfterCollapse(NodeID id)
Definition: SVFIR.cpp:499
SVFStmtList & getSVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PAGEdges.
Definition: SVFIR.h:221
bool hasSVFStmtList(const ICFGNode *inst) const
Whether this instruction has SVFIR Edge.
Definition: SVFIR.h:211
std::vector< const SVFVar * > SVFVarList
Definition: SVFIR.h:59
std::vector< const SVFStmt * > SVFStmtList
Definition: SVFIR.h:58
NodeID getBaseObjVar(NodeID id) const
Base and Offset methods for Value and Object node.
Definition: SVFIR.h:455
bool hasCallSiteArgsMap(const CallICFGNode *cs) const
Callsite has argument list.
Definition: SVFIR.h:282
const CallSiteSet & getCallSiteSet() const
Get all callsites.
Definition: SVFIR.h:254
bool callsiteHasRet(const RetICFGNode *cs) const
Definition: SVFIR.h:310
SVFStmtList & getPTASVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PTA PAGEdges.
Definition: SVFIR.h:226
virtual bool isPointer() const
Whether it is a pointer.
Definition: SVFVariables.h:106
virtual const SVFFunction * getFunction() const
Return the function that this SVFVar resides in. Return nullptr if it is a global or constantexpr nod...
Definition: SVFVariables.h:122
bool test(unsigned Idx) const
bool intersects(const SparseBitVector< ElementSize > *RHS) const
iterator end() const
void set(unsigned Idx)
bool contains(const SparseBitVector< ElementSize > &RHS) const
iterator begin() const
bool isHeapAllocExtCall(const Instruction *inst)
Definition: LLVMUtil.h:358
bool isExtCall(const SVFFunction *fun)
Definition: SVFUtil.h:278
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
Definition: SVFUtil.cpp:99
std::ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:50
for isBitcode
Definition: BasicTypes.h:68
std::stack< NodeID > NodeStack
Definition: GeneralType.h:118
ModRefInfo
Definition: SVFType.h:519
@ Ref
Definition: SVFType.h:521
@ NoModRef
Definition: SVFType.h:523
@ ModRef
Definition: SVFType.h:520
@ Mod
Definition: SVFType.h:522
u32_t NodeID
Definition: GeneralType.h:55
IntervalValue operator<<(const IntervalValue &lhs, const IntervalValue &rhs)
Left binary shift of IntervalValues.