From 545b456622b27879b4bd0ccbea1efc775ce665e0 Mon Sep 17 00:00:00 2001 From: George Karpenkov Date: Wed, 11 Jul 2018 01:23:27 +0000 Subject: [PATCH] [analyzer] Pass through all arguments from the registerChecker() to the checker constructor 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 --- .../StaticAnalyzer/Core/CheckerManager.h | 23 ++++--------------- .../Checkers/DynamicTypePropagation.cpp | 15 ++++++------ 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/include/clang/StaticAnalyzer/Core/CheckerManager.h b/include/clang/StaticAnalyzer/Core/CheckerManager.h index 9d87b440dc..99a8eb01fa 100644 --- a/include/clang/StaticAnalyzer/Core/CheckerManager.h +++ b/include/clang/StaticAnalyzer/Core/CheckerManager.h @@ -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 - CHECKER *registerChecker() { - CheckerTag tag = getTag(); - CheckerRef &ref = CheckerTags[tag]; - if (ref) - return static_cast(ref); // already registered. - - CHECKER *checker = new CHECKER(); - checker->Name = CurrentCheckName; - CheckerDtors.push_back(CheckerDtor(checker, destruct)); - CHECKER::_register(checker, *this); - ref = checker; - return checker; - } - - template - CHECKER *registerChecker(AnalyzerOptions &AOpts) { + template + CHECKER *registerChecker(AT... Args) { CheckerTag tag = getTag(); CheckerRef &ref = CheckerTags[tag]; if (ref) return static_cast(ref); // already registered. - CHECKER *checker = new CHECKER(AOpts); + CHECKER *checker = new CHECKER(Args...); checker->Name = CurrentCheckName; CheckerDtors.push_back(CheckerDtor(checker, destruct)); CHECKER::_register(checker, *this); diff --git a/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp b/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp index 126e57645a..914ba86850 100644 --- a/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp +++ b/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp @@ -56,6 +56,12 @@ class DynamicTypePropagation: check::PostStmt, 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(); - checker->CheckGenerics = true; + mgr.registerChecker(/*CheckGenerics=*/true); } void ento::registerDynamicTypePropagation(CheckerManager &mgr) { - mgr.registerChecker(); + mgr.registerChecker(/*CheckGenerics=*/false); } -- 2.40.0