[analyzer] Enable the self-init checker under command-line option '-analyzer-check-objc-self-init' which by default
is enabled by the driver for '--analyze'.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124266 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index e245f78..90ed5d4 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -910,6 +910,7 @@
       if (types::isObjC(InputType)) {
         CmdArgs.push_back("-analyzer-check-objc-methodsigs");
         CmdArgs.push_back("-analyzer-check-objc-unused-ivars");
+        CmdArgs.push_back("-analyzer-check-objc-self-init");
         // Do not enable the missing -dealloc check.
         // '-analyzer-check-objc-missing-dealloc',
       }
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index c3f3dbd..28cae64 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -118,6 +118,8 @@
     Res.push_back("-analyzer-experimental-internal-checks");
   if (Opts.IdempotentOps)
     Res.push_back("-analyzer-check-idempotent-operations");
+  if (Opts.ObjCSelfInitCheck)
+    Res.push_back("-analyzer-check-objc-self-init");
   if (Opts.BufferOverflows)
     Res.push_back("-analyzer-check-buffer-overflows");
 }
@@ -868,6 +870,7 @@
   Opts.MaxLoop = Args.getLastArgIntValue(OPT_analyzer_max_loop, 4, Diags);
   Opts.InlineCall = Args.hasArg(OPT_analyzer_inline_call);
   Opts.IdempotentOps = Args.hasArg(OPT_analysis_WarnIdempotentOps);
+  Opts.ObjCSelfInitCheck = Args.hasArg(OPT_analysis_WarnObjCSelfInit);
   Opts.BufferOverflows = Args.hasArg(OPT_analysis_WarnBufferOverflows);
 }
 
diff --git a/lib/StaticAnalyzer/Checkers/AnalysisConsumer.cpp b/lib/StaticAnalyzer/Checkers/AnalysisConsumer.cpp
index ae8732a..9190e2d 100644
--- a/lib/StaticAnalyzer/Checkers/AnalysisConsumer.cpp
+++ b/lib/StaticAnalyzer/Checkers/AnalysisConsumer.cpp
@@ -357,6 +357,9 @@
   if (C.Opts.EnableExperimentalChecks)
     RegisterExperimentalChecks(Eng);
 
+  if (C.Opts.ObjCSelfInitCheck && isa<ObjCMethodDecl>(D))
+    registerObjCSelfInitChecker(Eng);
+
   // Enable idempotent operation checking if it was explicitly turned on, or if
   // we are running experimental checks (i.e. everything)
   if (C.Opts.IdempotentOps || C.Opts.EnableExperimentalChecks
diff --git a/lib/StaticAnalyzer/Checkers/ExprEngine.cpp b/lib/StaticAnalyzer/Checkers/ExprEngine.cpp
index f311bea..8ad094b 100644
--- a/lib/StaticAnalyzer/Checkers/ExprEngine.cpp
+++ b/lib/StaticAnalyzer/Checkers/ExprEngine.cpp
@@ -309,7 +309,6 @@
   RegisterUndefResultChecker(Eng);
   RegisterStackAddrLeakChecker(Eng);
   RegisterObjCAtSyncChecker(Eng);
-  registerObjCSelfInitChecker(Eng);
 
   // This is not a checker yet.
   RegisterNoReturnFunctionChecker(Eng);