[cfe-commits] r126615 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/Checkers.td lib/StaticAnalyzer/Checkers/ExprEngine.cpp lib/StaticAnalyzer/Checkers/InternalChecks.h lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp test/Analysis/blocks.m

Argyrios Kyrtzidis akyrtzi at gmail.com
Sun Feb 27 17:27:27 PST 2011


Author: akirtzidis
Date: Sun Feb 27 19:27:26 2011
New Revision: 126615

URL: http://llvm.org/viewvc/llvm-project?rev=126615&view=rev
Log:
[analyzer] Migrate UndefCapturedBlockVarChecker to CheckerV2.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td
    cfe/trunk/lib/StaticAnalyzer/Checkers/ExprEngine.cpp
    cfe/trunk/lib/StaticAnalyzer/Checkers/InternalChecks.h
    cfe/trunk/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp
    cfe/trunk/test/Analysis/blocks.m

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td?rev=126615&r1=126614&r2=126615&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td Sun Feb 27 19:27:26 2011
@@ -75,6 +75,10 @@
 
 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">;

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/ExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/ExprEngine.cpp?rev=126615&r1=126614&r2=126615&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ExprEngine.cpp Sun Feb 27 19:27:26 2011
@@ -331,7 +331,6 @@
   RegisterUndefinedArraySubscriptChecker(Eng);
   RegisterUndefinedAssignmentChecker(Eng);
   RegisterUndefBranchChecker(Eng);
-  RegisterUndefCapturedBlockVarChecker(Eng);
 }
 
 ExprEngine::ExprEngine(AnalysisManager &mgr, TransferFuncs *tf)

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/InternalChecks.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/InternalChecks.h?rev=126615&r1=126614&r2=126615&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/InternalChecks.h (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/InternalChecks.h Sun Feb 27 19:27:26 2011
@@ -29,7 +29,6 @@
 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);

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp?rev=126615&r1=126614&r2=126615&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp Sun Feb 27 19:27:26 2011
@@ -11,8 +11,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#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 @@
 
 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 @@
 }
 
 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 @@
     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 @@
       }
   }
 }
+
+void ento::registerUndefCapturedBlockVarChecker(CheckerManager &mgr) {
+  mgr.registerChecker<UndefCapturedBlockVarChecker>();
+}

Modified: cfe/trunk/test/Analysis/blocks.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/blocks.m?rev=126615&r1=126614&r2=126615&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/blocks.m (original)
+++ cfe/trunk/test/Analysis/blocks.m Sun Feb 27 19:27:26 2011
@@ -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:





More information about the cfe-commits mailing list