[cfe-commits] r126307 - in /cfe/trunk/lib/StaticAnalyzer/Checkers: NSAutoreleasePoolChecker.cpp ObjCAtSyncChecker.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Feb 22 23:19:18 PST 2011


Author: akirtzidis
Date: Wed Feb 23 01:19:18 2011
New Revision: 126307

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

	NSAutoreleasePoolChecker
	ObjCAtSyncChecker

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp
    cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp?rev=126307&r1=126306&r2=126307&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp Wed Feb 23 01:19:18 2011
@@ -16,10 +16,11 @@
 //===----------------------------------------------------------------------===//
 
 #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/BugReporter/BugReporter.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerVisitor.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/Decl.h"
 
@@ -28,39 +29,18 @@
 
 namespace {
 class NSAutoreleasePoolChecker
-  : public CheckerVisitor<NSAutoreleasePoolChecker> {
+  : public CheckerV2<check::PreObjCMessage> {
       
-  Selector releaseS;
+  mutable Selector releaseS;
 
 public:
-    NSAutoreleasePoolChecker(Selector release_s) : releaseS(release_s) {}
-    
-  static void *getTag() {
-    static int x = 0;
-    return &x;
-  }
-
-  void preVisitObjCMessage(CheckerContext &C, ObjCMessage msg);    
+  void checkPreObjCMessage(ObjCMessage msg, CheckerContext &C) const;    
 };
 
 } // end anonymous namespace
 
-
-static void RegisterNSAutoreleasePoolChecker(ExprEngine &Eng) {
-  ASTContext &Ctx = Eng.getContext();
-  if (Ctx.getLangOptions().getGCMode() != LangOptions::NonGC) {    
-    Eng.registerCheck(new NSAutoreleasePoolChecker(GetNullarySelector("release",
-                                                                      Ctx)));
-  }
-}
-
-void ento::registerNSAutoreleasePoolChecker(CheckerManager &mgr) {
-  mgr.addCheckerRegisterFunction(RegisterNSAutoreleasePoolChecker);
-}
-
-void
-NSAutoreleasePoolChecker::preVisitObjCMessage(CheckerContext &C,
-                                              ObjCMessage msg) {
+void NSAutoreleasePoolChecker::checkPreObjCMessage(ObjCMessage msg,
+                                                   CheckerContext &C) const {
   
   const Expr *receiver = msg.getInstanceReceiver();
   if (!receiver)
@@ -78,7 +58,9 @@
     return;  
   if (!OD->getIdentifier()->getName().equals("NSAutoreleasePool"))
     return;
-  
+
+  if (releaseS.isNull())
+    releaseS = GetNullarySelector("release", C.getASTContext());
   // Sending 'release' message?
   if (msg.getSelector() != releaseS)
     return;
@@ -90,3 +72,8 @@
     "Use -drain instead of -release when using NSAutoreleasePool "
     "and garbage collection", R.getBegin(), &R, 1);
 }
+
+void ento::registerNSAutoreleasePoolChecker(CheckerManager &mgr) {
+  if (mgr.getLangOptions().getGCMode() != LangOptions::NonGC)
+    mgr.registerChecker<NSAutoreleasePoolChecker>();
+}

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp?rev=126307&r1=126306&r2=126307&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp Wed Feb 23 01:19:18 2011
@@ -13,39 +13,29 @@
 //===----------------------------------------------------------------------===//
 
 #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/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Checkers/DereferenceChecker.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerVisitor.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
 
 using namespace clang;
 using namespace ento;
 
 namespace {
-class ObjCAtSyncChecker : public CheckerVisitor<ObjCAtSyncChecker> {
-  BuiltinBug *BT_null;
-  BuiltinBug *BT_undef;
+class ObjCAtSyncChecker
+    : public CheckerV2< check::PreStmt<ObjCAtSynchronizedStmt> > {
+  mutable llvm::OwningPtr<BuiltinBug> BT_null;
+  mutable llvm::OwningPtr<BuiltinBug> BT_undef;
+
 public:
-  ObjCAtSyncChecker() : BT_null(0), BT_undef(0) {}
-  static void *getTag() { static int tag = 0; return &tag; }
-  void PreVisitObjCAtSynchronizedStmt(CheckerContext &C,
-                                      const ObjCAtSynchronizedStmt *S);
+  void checkPreStmt(const ObjCAtSynchronizedStmt *S, CheckerContext &C) const;
 };
 } // end anonymous namespace
 
-static void RegisterObjCAtSyncChecker(ExprEngine &Eng) {
-  // @synchronized is an Objective-C 2 feature.
-  if (Eng.getContext().getLangOptions().ObjC2)
-    Eng.registerCheck(new ObjCAtSyncChecker());
-}
-
-void ento::registerObjCAtSyncChecker(CheckerManager &mgr) {
-  mgr.addCheckerRegisterFunction(RegisterObjCAtSyncChecker);
-}
-
-void ObjCAtSyncChecker::PreVisitObjCAtSynchronizedStmt(CheckerContext &C,
-                                         const ObjCAtSynchronizedStmt *S) {
+void ObjCAtSyncChecker::checkPreStmt(const ObjCAtSynchronizedStmt *S,
+                                     CheckerContext &C) const {
 
   const Expr *Ex = S->getSynchExpr();
   const GRState *state = C.getState();
@@ -55,8 +45,8 @@
   if (isa<UndefinedVal>(V)) {
     if (ExplodedNode *N = C.generateSink()) {
       if (!BT_undef)
-        BT_undef = new BuiltinBug("Uninitialized value used as mutex "
-                                  "for @synchronized");
+        BT_undef.reset(new BuiltinBug("Uninitialized value used as mutex "
+                                  "for @synchronized"));
       EnhancedBugReport *report =
         new EnhancedBugReport(*BT_undef, BT_undef->getDescription(), N);
       report->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, Ex);
@@ -78,8 +68,8 @@
       // a null mutex just means no synchronization occurs.
       if (ExplodedNode *N = C.generateNode(nullState)) {
         if (!BT_null)
-          BT_null = new BuiltinBug("Nil value used as mutex for @synchronized() "
-                                   "(no synchronization will occur)");
+          BT_null.reset(new BuiltinBug("Nil value used as mutex for @synchronized() "
+                                   "(no synchronization will occur)"));
         EnhancedBugReport *report =
           new EnhancedBugReport(*BT_null, BT_null->getDescription(), N);
         report->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue,
@@ -98,3 +88,7 @@
     C.addTransition(notNullState);
 }
 
+void ento::registerObjCAtSyncChecker(CheckerManager &mgr) {
+  if (mgr.getLangOptions().ObjC2)
+    mgr.registerChecker<ObjCAtSyncChecker>();
+}





More information about the cfe-commits mailing list