diff options
author | Anna Zaks <ganna@apple.com> | 2012-02-08 23:16:52 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2012-02-08 23:16:52 +0000 |
commit | 231361ad343d655e4bbb1574ccbb4173b72dadfd (patch) | |
tree | 8edd07e49e169ace920b7a18aedc5ef6bc7bafe5 /lib/StaticAnalyzer/Checkers/MallocChecker.cpp | |
parent | af84f8fea486dde096466e85f4bca7c8d3ff4571 (diff) |
[analyzer] Split the MallocChecker into two versions - pessimistic and
optimistic.
TODO: actually implement the pessimistic version of the checker. Ex: it
needs to assume that any function that takes a pointer might free it.
The optimistic version relies on annotations to tell us which functions
can free the pointer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150111 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Checkers/MallocChecker.cpp')
-rw-r--r-- | lib/StaticAnalyzer/Checkers/MallocChecker.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 3e66929fdb..b14b400202 100644 --- a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -83,6 +83,16 @@ class MallocChecker : public Checker<check::DeadSymbols, public: MallocChecker() : II_malloc(0), II_free(0), II_realloc(0), II_calloc(0) {} + + /// In pessimistic mode, the checker assumes that it does not know which + /// functions might free the memory. + struct ChecksFilter { + DefaultBool CMallocPessimistic; + DefaultBool CMallocOptimistic; + }; + + ChecksFilter Filter; + void initIdentifierInfo(CheckerContext &C) const; void checkPostStmt(const CallExpr *CE, CheckerContext &C) const; @@ -750,6 +760,10 @@ void MallocChecker::checkBind(SVal location, SVal val, } } -void ento::registerMallocChecker(CheckerManager &mgr) { - mgr.registerChecker<MallocChecker>(); +#define REGISTER_CHECKER(name) \ +void ento::register##name(CheckerManager &mgr) {\ + mgr.registerChecker<MallocChecker>()->Filter.C##name = true;\ } + +REGISTER_CHECKER(MallocPessimistic) +REGISTER_CHECKER(MallocOptimistic) |