]> granicus.if.org Git - clang/commitdiff
[analyzer] Use a lazily-initialized BugType in ObjCSelfInitChecker.
authorJordan Rose <jordan_rose@apple.com>
Wed, 7 May 2014 03:30:04 +0000 (03:30 +0000)
committerJordan Rose <jordan_rose@apple.com>
Wed, 7 May 2014 03:30:04 +0000 (03:30 +0000)
Follow-up to Nico's leak-stopping patch in r208110.

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

lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp

index 3eec6815c9049c582463e655a8ccebba3978b343..51bc7e66dce2d9c7c4d653bce19bf1d19cd8b788 100644 (file)
@@ -55,13 +55,6 @@ static bool isInitMessage(const ObjCMethodCall &Msg);
 static bool isSelfVar(SVal location, CheckerContext &C);
 
 namespace {
-class InitSelfBug : public BugType {
-public:
-  InitSelfBug(const CheckerBase *Checker)
-      : BugType(Checker, "Missing \"self = [(super or self) init...]\"",
-                categories::CoreFoundationObjectiveC) {}
-};
-
 class ObjCSelfInitChecker : public Checker<  check::PostObjCMessage,
                                              check::PostStmt<ObjCIvarRefExpr>,
                                              check::PreStmt<ReturnStmt>,
@@ -69,13 +62,13 @@ class ObjCSelfInitChecker : public Checker<  check::PostObjCMessage,
                                              check::PostCall,
                                              check::Location,
                                              check::Bind > {
-  mutable InitSelfBug InitSelfBugType;
+  mutable std::unique_ptr<BugType> BT;
 
   void checkForInvalidSelf(const Expr *E, CheckerContext &C,
                            const char *errorStr) const;
 
 public:
-  ObjCSelfInitChecker() : InitSelfBugType(this) {}
+  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;
@@ -164,7 +157,10 @@ void ObjCSelfInitChecker::checkForInvalidSelf(const Expr *E, CheckerContext &C,
   if (!N)
     return;
 
-  BugReport *report = new BugReport(InitSelfBugType, 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);
 }