[analyzer] Migrate UndefBranchChecker to CheckerV2.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126616 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/StaticAnalyzer/Checkers/Checkers.td b/lib/StaticAnalyzer/Checkers/Checkers.td
index 6599b96..1a2205f 100644
--- a/lib/StaticAnalyzer/Checkers/Checkers.td
+++ b/lib/StaticAnalyzer/Checkers/Checkers.td
@@ -75,6 +75,10 @@
 
 let ParentPackage = Core in {
 
+def UndefBranchChecker : Checker<"UndefBranch">,
+  HelpText<"Check for undefined branch conditions">,
+  DescFile<"UndefBranchChecker.cpp">;
+
 def UndefCapturedBlockVarChecker : Checker<"UndefBlockVar">,
   HelpText<"Check for blocks that capture uninitialized values">,
   DescFile<"UndefCapturedBlockVarChecker.cpp">;
diff --git a/lib/StaticAnalyzer/Checkers/ExprEngine.cpp b/lib/StaticAnalyzer/Checkers/ExprEngine.cpp
index f39c7b9..00d1378 100644
--- a/lib/StaticAnalyzer/Checkers/ExprEngine.cpp
+++ b/lib/StaticAnalyzer/Checkers/ExprEngine.cpp
@@ -330,7 +330,6 @@
   RegisterReturnUndefChecker(Eng);
   RegisterUndefinedArraySubscriptChecker(Eng);
   RegisterUndefinedAssignmentChecker(Eng);
-  RegisterUndefBranchChecker(Eng);
 }
 
 ExprEngine::ExprEngine(AnalysisManager &mgr, TransferFuncs *tf)
@@ -1319,6 +1318,8 @@
     checker->VisitBranchCondition(builder, *this, Condition, tag);
   }
 
+  getCheckerManager().runCheckersForBranchCondition(Condition, builder, *this);
+
   // If the branch condition is undefined, return;
   if (!builder.isFeasible(true) && !builder.isFeasible(false))
     return;
diff --git a/lib/StaticAnalyzer/Checkers/InternalChecks.h b/lib/StaticAnalyzer/Checkers/InternalChecks.h
index 421b616..42bd968 100644
--- a/lib/StaticAnalyzer/Checkers/InternalChecks.h
+++ b/lib/StaticAnalyzer/Checkers/InternalChecks.h
@@ -28,7 +28,6 @@
 void RegisterDereferenceChecker(ExprEngine &Eng);
 void RegisterDivZeroChecker(ExprEngine &Eng);
 void RegisterReturnUndefChecker(ExprEngine &Eng);
-void RegisterUndefBranchChecker(ExprEngine &Eng);
 void RegisterUndefinedArraySubscriptChecker(ExprEngine &Eng);
 void RegisterUndefinedAssignmentChecker(ExprEngine &Eng);
 void RegisterVLASizeChecker(ExprEngine &Eng);
diff --git a/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp b/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp
index 14ae9ed..0902d91 100644
--- a/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp
@@ -12,17 +12,19 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "InternalChecks.h"
+#include "ClangSACheckers.h"
+#include "clang/StaticAnalyzer/Core/CheckerV2.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/Checker.h"
 
 using namespace clang;
 using namespace ento;
 
 namespace {
 
-class UndefBranchChecker : public Checker {
-  BuiltinBug *BT;
+class UndefBranchChecker : public CheckerV2<check::BranchCondition> {
+  mutable llvm::OwningPtr<BuiltinBug> BT;
 
   struct FindUndefExpr {
     GRStateManager& VM;
@@ -48,26 +50,15 @@
   };
 
 public:
-  UndefBranchChecker() : BT(0) {}
-  static void *getTag();
-  void VisitBranchCondition(BranchNodeBuilder &Builder, ExprEngine &Eng,
-                            const Stmt *Condition, void *tag);
+  void checkBranchCondition(const Stmt *Condition, BranchNodeBuilder &Builder,
+                            ExprEngine &Eng) const;
 };
 
 }
 
-void ento::RegisterUndefBranchChecker(ExprEngine &Eng) {
-  Eng.registerCheck(new UndefBranchChecker());
-}
-
-void *UndefBranchChecker::getTag() {
-  static int x;
-  return &x;
-}
-
-void UndefBranchChecker::VisitBranchCondition(BranchNodeBuilder &Builder, 
-                                              ExprEngine &Eng,
-                                              const Stmt *Condition, void *tag){
+void UndefBranchChecker::checkBranchCondition(const Stmt *Condition,
+                                              BranchNodeBuilder &Builder,
+                                              ExprEngine &Eng) const {
   const GRState *state = Builder.getState();
   SVal X = state->getSVal(Condition);
   if (X.isUndef()) {
@@ -75,7 +66,8 @@
     if (N) {
       N->markAsSink();
       if (!BT)
-        BT = new BuiltinBug("Branch condition evaluates to a garbage value");
+        BT.reset(
+               new BuiltinBug("Branch condition evaluates to a garbage value"));
 
       // What's going on here: we want to highlight the subexpression of the
       // condition that is the most likely source of the "uninitialized
@@ -118,3 +110,7 @@
     Builder.markInfeasible(false);
   }
 }
+
+void ento::registerUndefBranchChecker(CheckerManager &mgr) {
+  mgr.registerChecker<UndefBranchChecker>();
+}