]> granicus.if.org Git - clang/commitdiff
[analyzer] Migrate UndefCapturedBlockVarChecker to CheckerV2.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 28 Feb 2011 01:27:26 +0000 (01:27 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 28 Feb 2011 01:27:26 +0000 (01:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126615 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/Checkers.td
lib/StaticAnalyzer/Checkers/ExprEngine.cpp
lib/StaticAnalyzer/Checkers/InternalChecks.h
lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp
test/Analysis/blocks.m

index 7438a640568d7c8be40add185da4b8e1ebfb554a..6599b96b003038ce192d760bd49c1203dd272489 100644 (file)
@@ -75,6 +75,10 @@ def ObjCUnusedIvarsChecker : Checker<"UnusedIvars">,
 
 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">;
index 53a77862d6d72cca933cfb0e5480f0655d3d03c9..f39c7b9d73fe6a84417bb4ae7e1c244285b8d7a1 100644 (file)
@@ -331,7 +331,6 @@ static void RegisterInternalChecks(ExprEngine &Eng) {
   RegisterUndefinedArraySubscriptChecker(Eng);
   RegisterUndefinedAssignmentChecker(Eng);
   RegisterUndefBranchChecker(Eng);
-  RegisterUndefCapturedBlockVarChecker(Eng);
 }
 
 ExprEngine::ExprEngine(AnalysisManager &mgr, TransferFuncs *tf)
index d1cf7e836988fc2d60efbc818d6e4c9cf98f62d2..421b616456dd4353239975f30603c3a5db3edfbb 100644 (file)
@@ -29,7 +29,6 @@ void RegisterDereferenceChecker(ExprEngine &Eng);
 void RegisterDivZeroChecker(ExprEngine &Eng);
 void RegisterReturnUndefChecker(ExprEngine &Eng);
 void RegisterUndefBranchChecker(ExprEngine &Eng);
-void RegisterUndefCapturedBlockVarChecker(ExprEngine &Eng);
 void RegisterUndefinedArraySubscriptChecker(ExprEngine &Eng);
 void RegisterUndefinedAssignmentChecker(ExprEngine &Eng);
 void RegisterVLASizeChecker(ExprEngine &Eng);
index 6d3c966e6db14c2df4a37a6975de6535649553ae..718aa75da7c76a30acef5175999124bd1a94336b 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
-#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"
@@ -22,20 +24,14 @@ using namespace ento;
 
 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))
@@ -54,8 +50,8 @@ static const BlockDeclRefExpr *FindBlockDeclRefExpr(const Stmt *S,
 }
 
 void
-UndefCapturedBlockVarChecker::PostVisitBlockExpr(CheckerContext &C,
-                                                 const BlockExpr *BE) {
+UndefCapturedBlockVarChecker::checkPostStmt(const BlockExpr *BE,
+                                            CheckerContext &C) const {
   if (!BE->getBlockDecl()->hasCaptures())
     return;
 
@@ -82,7 +78,7 @@ UndefCapturedBlockVarChecker::PostVisitBlockExpr(CheckerContext &C,
     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;
@@ -100,3 +96,7 @@ UndefCapturedBlockVarChecker::PostVisitBlockExpr(CheckerContext &C,
       }
   }
 }
+
+void ento::registerUndefCapturedBlockVarChecker(CheckerManager &mgr) {
+  mgr.registerChecker<UndefCapturedBlockVarChecker>();
+}
index e18d7cfb7be6b32519e1e8b8ff53dc428ddae8f2..5287fa9e799183387653575e12192e3d3ff403a5 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-check-objc-mem -analyzer-store=region -fblocks -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core -analyzer-check-objc-mem -analyzer-store=region -fblocks -verify %s
 
 //===----------------------------------------------------------------------===//
 // The following code is reduced using delta-debugging from Mac OS X headers: