summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2012-02-08 23:16:52 +0000
committerAnna Zaks <ganna@apple.com>2012-02-08 23:16:52 +0000
commitcd37bf4ec8e2043dc589a592df5c97144b5dee3b (patch)
tree342578383bc391c0d7f045ce928f459f83b22368 /clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
parent7df15cd21f2db1b0665bc01e24f5ab889609e99f (diff)
downloadbcm5719-llvm-cd37bf4ec8e2043dc589a592df5c97144b5dee3b.tar.gz
bcm5719-llvm-cd37bf4ec8e2043dc589a592df5c97144b5dee3b.zip
[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. llvm-svn: 150111
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 3e66929fdbe..b14b4002022 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/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)
OpenPOWER on IntegriCloud