r208155 - [analyzer] Use a lazily-initialized BugType in ObjCSelfInitChecker.

Jordan Rose jordan_rose at apple.com
Tue May 6 20:30:04 PDT 2014


Author: jrose
Date: Tue May  6 22:30:04 2014
New Revision: 208155

URL: http://llvm.org/viewvc/llvm-project?rev=208155&view=rev
Log:
[analyzer] Use a lazily-initialized BugType in ObjCSelfInitChecker.

Follow-up to Nico's leak-stopping patch in r208110.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp?rev=208155&r1=208154&r2=208155&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp Tue May  6 22:30:04 2014
@@ -55,13 +55,6 @@ static bool isInitMessage(const ObjCMeth
 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 Check
                                              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::checkForInvali
   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);
 }
 





More information about the cfe-commits mailing list