diff options
-rw-r--r-- | lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp | 2 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp | 2 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp | 20 | ||||
-rw-r--r-- | test/Analysis/self-init.m | 20 |
4 files changed, 25 insertions, 19 deletions
diff --git a/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp b/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp index fc24c1888b..fe08438942 100644 --- a/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp @@ -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); } diff --git a/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp b/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp index f781f0ab8a..2a677bc3dd 100644 --- a/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp @@ -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 { diff --git a/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp b/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp index 65f2c73496..dbbab4891c 100644 --- a/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp @@ -34,18 +34,8 @@ // 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, diff --git a/test/Analysis/self-init.m b/test/Analysis/self-init.m index 019fdcd0c2..c79aa0ada4 100644 --- a/test/Analysis/self-init.m +++ b/test/Analysis/self-init.m @@ -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 |