Static Value-Flow Analysis
LeakChecker.h
Go to the documentation of this file.
1 //===- LeakChecker.h -- Detecting memory leaks--------------------------------//
2 //
3 // SVF: Static Value-Flow Analysis
4 //
5 // Copyright (C) <2013-> <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  * LeakChecker.h
25  *
26  * Created on: Apr 1, 2014
27  * Author: rockysui
28  */
29 
30 #ifndef LEAKCHECKER_H_
31 #define LEAKCHECKER_H_
32 
33 #include "SABER/SrcSnkDDA.h"
34 #include "SABER/SaberCheckerAPI.h"
35 
36 namespace SVF
37 {
38 
42 class LeakChecker : public SrcSnkDDA
43 {
44 
45 public:
49  typedef NodeBS SVFGNodeBS;
50  enum LEAK_TYPE
51  {
56  };
57 
60  {
61  }
63  virtual ~LeakChecker()
64  {
65  }
66 
68  virtual bool runOnModule(SVFIR* pag)
69  {
71  analyze(pag->getModule());
72  return false;
73  }
74 
76 
77  virtual void initSrcs() override;
79  virtual void initSnks() override;
81  virtual inline bool isSourceLikeFun(const SVFFunction* fun) override
82  {
84  }
86  virtual inline bool isSinkLikeFun(const SVFFunction* fun) override
87  {
89  }
91 
92 protected:
94 
95  virtual void reportBug(ProgSlice* slice) override;
97 
99  void testsValidation(const ProgSlice* slice);
100  void validateSuccessTests(const SVFGNode* source, const SVFFunction* fun);
101  void validateExpectedFailureTests(const SVFGNode* source, const SVFFunction* fun);
102 
104 
105  inline void addSrcToCSID(const SVFGNode* src, const CallICFGNode* cs)
106  {
107  srcToCSIDMap[src] = cs;
108  }
109  inline const CallICFGNode* getSrcCSID(const SVFGNode* src)
110  {
111  SVFGNodeToCSIDMap::iterator it =srcToCSIDMap.find(src);
112  assert(it!=srcToCSIDMap.end() && "source node not at a callsite??");
113  return it->second;
114  }
116 private:
118 };
119 
120 } // End namespace SVF
121 
122 #endif /* LEAKCHECKER_H_ */
void validateSuccessTests(const SVFGNode *source, const SVFFunction *fun)
void addSrcToCSID(const SVFGNode *src, const CallICFGNode *cs)
Record a source to its callsite.
Definition: LeakChecker.h:105
virtual bool runOnModule(SVFIR *pag)
We start from here.
Definition: LeakChecker.h:68
virtual ~LeakChecker()
Destructor.
Definition: LeakChecker.h:63
virtual void initSrcs() override
Initialize sources and sinks.
Definition: LeakChecker.cpp:40
virtual void initSnks() override
SVFGNodeToCSIDMap srcToCSIDMap
Definition: LeakChecker.h:117
const CallICFGNode * getSrcCSID(const SVFGNode *src)
Definition: LeakChecker.h:109
Map< const SVFGNode *, const CallICFGNode * > SVFGNodeToCSIDMap
Definition: LeakChecker.h:46
FIFOWorkList< const CallICFGNode * > CSWorkList
Definition: LeakChecker.h:47
virtual bool isSinkLikeFun(const SVFFunction *fun) override
Whether the function is a heap deallocator (free/release memory)
Definition: LeakChecker.h:86
virtual void reportBug(ProgSlice *slice) override
Report leaks.
void testsValidation(const ProgSlice *slice)
Validate test cases for regression test purpose.
void validateExpectedFailureTests(const SVFGNode *source, const SVFFunction *fun)
LeakChecker()
Constructor.
Definition: LeakChecker.h:59
ProgSlice::VFWorkList WorkList
Definition: LeakChecker.h:48
virtual bool isSourceLikeFun(const SVFFunction *fun) override
Whether the function is a heap allocator/reallocator (allocate memory)
Definition: LeakChecker.h:81
SVFModule * getModule()
Definition: SVFIR.h:161
bool isMemAlloc(const SVFFunction *fun) const
Return true if this call is a memory allocation.
bool isMemDealloc(const SVFFunction *fun) const
Return true if this call is a memory deallocation.
static SaberCheckerAPI * getCheckerAPI()
Return a static reference.
virtual void analyze(SVFModule *module)
Start analysis here.
Definition: SrcSnkDDA.cpp:61
for isBitcode
Definition: BasicTypes.h:68
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition: GeneralType.h:101