]> granicus.if.org Git - clang/commitdiff
[analyzer] Pass through all arguments from the registerChecker() to the checker const...
authorGeorge Karpenkov <ekarpenkov@apple.com>
Wed, 11 Jul 2018 01:23:27 +0000 (01:23 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Wed, 11 Jul 2018 01:23:27 +0000 (01:23 +0000)
A lot of checkers could be cleaned up in a similar way

Differential Revision: https://reviews.llvm.org/D49050

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

include/clang/StaticAnalyzer/Core/CheckerManager.h
lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp

index 9d87b440dc5f53bec540e64a84532e365c6c66a3..99a8eb01fa73bbc4f0830152df2e7f4fdd4e0d97 100644 (file)
@@ -144,31 +144,18 @@ public:
 //===----------------------------------------------------------------------===//
 
   /// Used to register checkers.
+  /// All arguments are automatically passed through to the checker
+  /// constructor.
   ///
   /// \returns a pointer to the checker object.
-  template <typename CHECKER>
-  CHECKER *registerChecker() {
-    CheckerTag tag = getTag<CHECKER>();
-    CheckerRef &ref = CheckerTags[tag];
-    if (ref)
-      return static_cast<CHECKER *>(ref); // already registered.
-
-    CHECKER *checker = new CHECKER();
-    checker->Name = CurrentCheckName;
-    CheckerDtors.push_back(CheckerDtor(checker, destruct<CHECKER>));
-    CHECKER::_register(checker, *this);
-    ref = checker;
-    return checker;
-  }
-
-  template <typename CHECKER>
-  CHECKER *registerChecker(AnalyzerOptions &AOpts) {
+  template <typename CHECKER, typename... AT>
+  CHECKER *registerChecker(AT... Args) {
     CheckerTag tag = getTag<CHECKER>();
     CheckerRef &ref = CheckerTags[tag];
     if (ref)
       return static_cast<CHECKER *>(ref); // already registered.
 
-    CHECKER *checker = new CHECKER(AOpts);
+    CHECKER *checker = new CHECKER(Args...);
     checker->Name = CurrentCheckName;
     CheckerDtors.push_back(CheckerDtor(checker, destruct<CHECKER>));
     CHECKER::_register(checker, *this);
index 126e57645a43b26a7ba5af110b41406ff91ec14b..914ba86850efd964e89c8f2b9d51edf40c32b7f8 100644 (file)
@@ -56,6 +56,12 @@ class DynamicTypePropagation:
                     check::PostStmt<CXXNewExpr>,
                     check::PreObjCMessage,
                     check::PostObjCMessage > {
+private:
+  /// This value is set to true, when the Generics checker is turned on.
+  bool CheckGenerics;
+public:
+  DynamicTypePropagation(bool CheckGenerics)
+      : CheckGenerics(CheckGenerics) {}
   const ObjCObjectType *getObjectTypeForAllocAndNew(const ObjCMessageExpr *MsgE,
                                                     CheckerContext &C) const;
 
@@ -107,9 +113,6 @@ public:
   void checkDeadSymbols(SymbolReaper &SR, CheckerContext &C) const;
   void checkPreObjCMessage(const ObjCMethodCall &M, CheckerContext &C) const;
   void checkPostObjCMessage(const ObjCMethodCall &M, CheckerContext &C) const;
-
-  /// This value is set to true, when the Generics checker is turned on.
-  DefaultBool CheckGenerics;
 };
 } // end anonymous namespace
 
@@ -995,11 +998,9 @@ DynamicTypePropagation::GenericsBugVisitor::VisitNode(const ExplodedNode *N,
 
 /// Register checkers.
 void ento::registerObjCGenericsChecker(CheckerManager &mgr) {
-  DynamicTypePropagation *checker =
-      mgr.registerChecker<DynamicTypePropagation>();
-  checker->CheckGenerics = true;
+  mgr.registerChecker<DynamicTypePropagation>(/*CheckGenerics=*/true);
 }
 
 void ento::registerDynamicTypePropagation(CheckerManager &mgr) {
-  mgr.registerChecker<DynamicTypePropagation>();
+  mgr.registerChecker<DynamicTypePropagation>(/*CheckGenerics=*/false);
 }