aboutsummaryrefslogtreecommitdiff
path: root/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp')
-rw-r--r--lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp42
1 files changed, 20 insertions, 22 deletions
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<BugType> 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,22 +80,11 @@ 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.
SelfFlag_None = 0x0,
@@ -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;