Hook up Malloc checker.

llvm-svn: 87093
This commit is contained in:
Zhongxing Xu 2009-11-13 07:25:27 +00:00
parent a4276b091d
commit c4902a52a0
3 changed files with 14 additions and 0 deletions

View File

@ -19,5 +19,6 @@ using namespace clang;
void clang::RegisterExperimentalChecks(GRExprEngine &Eng) {
RegisterPthreadLockChecker(Eng);
RegisterMallocChecker(Eng);
}

View File

@ -20,6 +20,7 @@ namespace clang {
class GRExprEngine;
void RegisterPthreadLockChecker(GRExprEngine &Eng);
void RegisterMallocChecker(GRExprEngine &Eng);
} // end clang namespace
#endif

View File

@ -12,6 +12,7 @@
//
//===----------------------------------------------------------------------===//
#include "GRExprEngineExperimentalChecks.h"
#include "clang/Analysis/PathSensitive/CheckerVisitor.h"
#include "clang/Analysis/PathSensitive/GRState.h"
#include "clang/Analysis/PathSensitive/GRStateTrait.h"
@ -33,8 +34,11 @@ class VISIBILITY_HIDDEN MallocChecker : public CheckerVisitor<MallocChecker> {
IdentifierInfo *II_free;
public:
MallocChecker() : BT_DoubleFree(0) {}
static void *getTag();
void PostVisitCallExpr(CheckerContext &C, const CallExpr *CE);
void EvalDeadSymbols(CheckerContext &C,const Stmt *S,SymbolReaper &SymReaper);
private:
void MallocMem(CheckerContext &C, const CallExpr *CE);
void FreeMem(CheckerContext &C, const CallExpr *CE);
};
@ -59,6 +63,10 @@ namespace clang {
};
}
void clang::RegisterMallocChecker(GRExprEngine &Eng) {
Eng.registerCheck(new MallocChecker());
}
void *MallocChecker::getTag() {
static int x;
return &x;
@ -124,3 +132,7 @@ void MallocChecker::FreeMem(CheckerContext &C, const CallExpr *CE) {
const GRState *FreedState = state->set<RegionState>(Sym, Released);
C.addTransition(C.GenerateNode(CE, FreedState));
}
void MallocChecker::EvalDeadSymbols(CheckerContext &C, const Stmt *S,
SymbolReaper &SymReaper) {
}