]> granicus.if.org Git - clang/commitdiff
[analyzer] Minor cleanups to the ObjCSelfInitChecker.
authorAnna Zaks <ganna@apple.com>
Sat, 4 Feb 2012 02:31:37 +0000 (02:31 +0000)
committerAnna Zaks <ganna@apple.com>
Sat, 4 Feb 2012 02:31:37 +0000 (02:31 +0000)
(Also renames in other ObjC checkers to create one category of checks.)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149745 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp
lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp
lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
test/Analysis/self-init.m

index fc24c1888b5765089da52bd03be92e583e558274..fe084389425f0dac82647696932497a81f9f43ab 100644 (file)
@@ -141,7 +141,7 @@ void WalkAST::VisitCallExpr(CallExpr *CE) {
     SourceRange R = Arg->getSourceRange();
     PathDiagnosticLocation CELoc =
         PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC);
-    BR.EmitBasicReport(OsName.str(), "Core Foundation/Objective-C API",
+    BR.EmitBasicReport(OsName.str(), "Core Foundation/Objective-C",
                        Os.str(), CELoc, &R, 1);
   }
 
index f781f0ab8afe066b9353355b0bb276c5fd6626ee..2a677bc3dd08acfbe26a18a97e7830a3206f4ad3 100644 (file)
@@ -34,7 +34,7 @@ class ObjCContainersChecker : public Checker< check::PreStmt<CallExpr>,
   mutable llvm::OwningPtr<BugType> BT;
   inline void initBugType() const {
     if (!BT)
-      BT.reset(new BugType("CFArray API", "Core Foundation/Objective-C API"));
+      BT.reset(new BugType("CFArray API", "Core Foundation/Objective-C"));
   }
 
   inline SymbolRef getArraySym(const Expr *E, CheckerContext &C) const {
index 65f2c734969ba3ac76af38ea00c09ae2d6b1c1d6..dbbab4891c34e804629a4e9ee4358c62005adbc2 100644 (file)
 // receives a reference to 'self', the checker keeps track and passes the flags
 // for 1) and 2) to the new object that 'self' points to after the call.
 //
-// FIXME (rdar://7937506): In the case of:
-//   [super init];
-//   return self;
-// Have an extra PathDiagnosticPiece in the path that says "called [super init],
-// but didn't assign the result to self."
-
 //===----------------------------------------------------------------------===//
 
-// FIXME: Somehow stick the link to Apple's documentation about initializing
-// objects in the diagnostics.
-// http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocAllocInit.html
-
 #include "ClangSACheckers.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
@@ -87,8 +77,8 @@ namespace {
 class InitSelfBug : public BugType {
   const std::string desc;
 public:
-  InitSelfBug() : BugType("missing \"self = [(super or self) init...]\"",
-                          "missing \"self = [(super or self) init...]\"") {}
+  InitSelfBug() : BugType("Missing \"self = [(super or self) init...]\"",
+                          "Core Foundation/Objective-C") {}
 };
 
 } // end anonymous namespace
@@ -194,7 +184,7 @@ void ObjCSelfInitChecker::checkPostObjCMessage(ObjCMessage msg,
 
   // FIXME: A callback should disable checkers at the start of functions.
   if (!shouldRunOnFunctionOrMethod(dyn_cast<NamedDecl>(
-                                     C.getCurrentAnalysisDeclContext()->getDecl())))
+                                C.getCurrentAnalysisDeclContext()->getDecl())))
     return;
 
   if (isInitMessage(msg)) {
@@ -221,7 +211,7 @@ void ObjCSelfInitChecker::checkPostStmt(const ObjCIvarRefExpr *E,
                                         CheckerContext &C) const {
   // FIXME: A callback should disable checkers at the start of functions.
   if (!shouldRunOnFunctionOrMethod(dyn_cast<NamedDecl>(
-                                     C.getCurrentAnalysisDeclContext()->getDecl())))
+                                 C.getCurrentAnalysisDeclContext()->getDecl())))
     return;
 
   checkForInvalidSelf(E->getBase(), C,
@@ -233,7 +223,7 @@ void ObjCSelfInitChecker::checkPreStmt(const ReturnStmt *S,
                                        CheckerContext &C) const {
   // FIXME: A callback should disable checkers at the start of functions.
   if (!shouldRunOnFunctionOrMethod(dyn_cast<NamedDecl>(
-                                     C.getCurrentAnalysisDeclContext()->getDecl())))
+                                 C.getCurrentAnalysisDeclContext()->getDecl())))
     return;
 
   checkForInvalidSelf(S->getRetValue(), C,
index 019fdcd0c2bfa3c4bffbaa5e08e11b8a6e1c4fe7..c79aa0ada42bae4e6bd4a35907c166dd27b79c7a 100644 (file)
@@ -147,13 +147,29 @@ static id _commonInit(MyObj *self) {
 }
 
 -(id)init14 {
-  if (!(self = [super init]))
-    return 0;
   if (!(self = _commonInit(self)))
     return 0;
   return self;
 }
 
+-(id)init15 {
+  if (!(self = [super init]))
+    return 0;
+  return self;
+}
+
+-(id)init16 {
+  somePtr = [super init];
+  self = somePtr;
+  myivar = 0; 
+  return self;
+}
+
+-(id)init17 {
+  somePtr = [super init];
+  myivar = 0; // expected-warning {{Instance variable used}}
+}
+
 -(void)doSomething {}
 
 @end