From 9f4dbff6669c8037f3b036bcf580d14f1a4f12a5 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 24 Nov 2014 09:15:30 +0000 Subject: Vendor import of clang RELEASE_350/final tag r216957 (effectively, 3.5.0 release): https://llvm.org/svn/llvm-project/cfe/tags/RELEASE_350/final@216957 --- .../Checkers/ObjCSelfInitChecker.cpp | 42 +++++++++++----------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp') diff --git a/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp b/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp index 8506e08b2b98..51bc7e66dce2 100644 --- a/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp @@ -62,7 +62,13 @@ class ObjCSelfInitChecker : public Checker< check::PostObjCMessage, check::PostCall, check::Location, check::Bind > { + mutable std::unique_ptr BT; + + void checkForInvalidSelf(const Expr *E, CheckerContext &C, + const char *errorStr) const; + public: + ObjCSelfInitChecker() {} void checkPostObjCMessage(const ObjCMethodCall &Msg, CheckerContext &C) const; void checkPostStmt(const ObjCIvarRefExpr *E, CheckerContext &C) const; void checkPreStmt(const ReturnStmt *S, CheckerContext &C) const; @@ -74,21 +80,10 @@ public: void checkPostCall(const CallEvent &CE, CheckerContext &C) const; void printState(raw_ostream &Out, ProgramStateRef State, - const char *NL, const char *Sep) const; + const char *NL, const char *Sep) const override; }; } // end anonymous namespace -namespace { - -class InitSelfBug : public BugType { - const std::string desc; -public: - InitSelfBug() : BugType("Missing \"self = [(super or self) init...]\"", - categories::CoreFoundationObjectiveC) {} -}; - -} // end anonymous namespace - namespace { enum SelfFlagEnum { /// \brief No flag set. @@ -146,8 +141,8 @@ static bool isInvalidSelf(const Expr *E, CheckerContext &C) { return true; } -static void checkForInvalidSelf(const Expr *E, CheckerContext &C, - const char *errorStr) { +void ObjCSelfInitChecker::checkForInvalidSelf(const Expr *E, CheckerContext &C, + const char *errorStr) const { if (!E) return; @@ -162,8 +157,10 @@ static void checkForInvalidSelf(const Expr *E, CheckerContext &C, if (!N) return; - BugReport *report = - new BugReport(*new InitSelfBug(), errorStr, N); + if (!BT) + BT.reset(new BugType(this, "Missing \"self = [(super or self) init...]\"", + categories::CoreFoundationObjectiveC)); + BugReport *report = new BugReport(*BT, errorStr, N); C.emitReport(report); } @@ -205,9 +202,10 @@ void ObjCSelfInitChecker::checkPostStmt(const ObjCIvarRefExpr *E, C.getCurrentAnalysisDeclContext()->getDecl()))) return; - checkForInvalidSelf(E->getBase(), C, - "Instance variable used while 'self' is not set to the result of " - "'[(super or self) init...]'"); + checkForInvalidSelf( + E->getBase(), C, + "Instance variable used while 'self' is not set to the result of " + "'[(super or self) init...]'"); } void ObjCSelfInitChecker::checkPreStmt(const ReturnStmt *S, @@ -218,8 +216,8 @@ void ObjCSelfInitChecker::checkPreStmt(const ReturnStmt *S, return; checkForInvalidSelf(S->getRetValue(), C, - "Returning 'self' while it is not set to the result of " - "'[(super or self) init...]'"); + "Returning 'self' while it is not set to the result of " + "'[(super or self) init...]'"); } // When a call receives a reference to 'self', [Pre/Post]Call pass @@ -347,7 +345,7 @@ void ObjCSelfInitChecker::printState(raw_ostream &Out, ProgramStateRef State, if (FlagMap.isEmpty() && !DidCallInit && !PreCallFlags) return; - Out << Sep << NL << "ObjCSelfInitChecker:" << NL; + Out << Sep << NL << *this << " :" << NL; if (DidCallInit) Out << " An init method has been called." << NL; -- cgit v1.3