let ParentPackage = Core in {
+def UndefCapturedBlockVarChecker : Checker<"UndefBlockVar">,
+ HelpText<"Check for blocks that capture uninitialized values">,
+ DescFile<"UndefCapturedBlockVarChecker.cpp">;
+
def UndefResultChecker : Checker<"UndefBinOpResult">,
HelpText<"Check for undefined results of non-assignment binary operators">,
DescFile<"UndefResultChecker.cpp">;
//
//===----------------------------------------------------------------------===//
-#include "InternalChecks.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerVisitor.h"
+#include "ClangSACheckers.h"
+#include "clang/StaticAnalyzer/Core/CheckerV2.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "llvm/Support/raw_ostream.h"
namespace {
class UndefCapturedBlockVarChecker
- : public CheckerVisitor<UndefCapturedBlockVarChecker> {
- BugType *BT;
+ : public CheckerV2< check::PostStmt<BlockExpr> > {
+ mutable llvm::OwningPtr<BugType> BT;
public:
- UndefCapturedBlockVarChecker() : BT(0) {}
- static void *getTag() { static int tag = 0; return &tag; }
- void PostVisitBlockExpr(CheckerContext &C, const BlockExpr *BE);
+ void checkPostStmt(const BlockExpr *BE, CheckerContext &C) const;
};
} // end anonymous namespace
-void ento::RegisterUndefCapturedBlockVarChecker(ExprEngine &Eng) {
- Eng.registerCheck(new UndefCapturedBlockVarChecker());
-}
-
static const BlockDeclRefExpr *FindBlockDeclRefExpr(const Stmt *S,
const VarDecl *VD){
if (const BlockDeclRefExpr *BR = dyn_cast<BlockDeclRefExpr>(S))
}
void
-UndefCapturedBlockVarChecker::PostVisitBlockExpr(CheckerContext &C,
- const BlockExpr *BE) {
+UndefCapturedBlockVarChecker::checkPostStmt(const BlockExpr *BE,
+ CheckerContext &C) const {
if (!BE->getBlockDecl()->hasCaptures())
return;
if (state->getSVal(VR).isUndef())
if (ExplodedNode *N = C.generateSink()) {
if (!BT)
- BT = new BuiltinBug("uninitialized variable captured by block");
+ BT.reset(new BuiltinBug("uninitialized variable captured by block"));
// Generate a bug report.
llvm::SmallString<128> buf;
}
}
}
+
+void ento::registerUndefCapturedBlockVarChecker(CheckerManager &mgr) {
+ mgr.registerChecker<UndefCapturedBlockVarChecker>();
+}