[clang] [analyzer][NFC] Introduce framework for checker families (PR #139256)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Tue May 13 02:44:44 PDT 2025


================
@@ -25,25 +25,23 @@ using namespace ento;
 using namespace taint;
 
 namespace {
-class DivZeroChecker : public Checker<check::PreStmt<BinaryOperator>> {
+class DivZeroChecker : public CheckerFamily<check::PreStmt<BinaryOperator>> {
   void reportBug(StringRef Msg, ProgramStateRef StateZero,
                  CheckerContext &C) const;
   void reportTaintBug(StringRef Msg, ProgramStateRef StateZero,
                       CheckerContext &C,
                       llvm::ArrayRef<SymbolRef> TaintedSyms) const;
 
 public:
-  /// This checker class implements several user facing checkers
-  enum : CheckerPartIdx {
-    DivideZeroChecker,
-    TaintedDivChecker,
-    NumCheckerParts
-  };
-  BugType BugTypes[NumCheckerParts] = {
-      {this, DivideZeroChecker, "Division by zero"},
-      {this, TaintedDivChecker, "Division by zero", categories::TaintedData}};
+  /// This checker family implements two user-facing checker parts.
+  CheckerFrontendWithBugType DivideZeroChecker{"Division by zero"},
+      TaintedDivChecker{"Division by zero", categories::TaintedData};
 
   void checkPreStmt(const BinaryOperator *B, CheckerContext &C) const;
+
+  /// Identifies this checker family for debugging purposes. For backwards
+  /// compatibility, this is the name of the older sub-checker.
+  StringRef getTagDescription() const override { return "core.DivideZero"; }
----------------
steakhal wrote:

I believe this `core.DivideZero` duplicates information from the `Checkers.td`.
If that's the case, then we should either make sure we don't duplicate this or hard-error if it would get out of sync.

The CheckerRegistry or one of its friend should have access to the checker dep graph to enable checker dependencies. This suggests to me that this information should be present and automatically deduced.

https://github.com/llvm/llvm-project/pull/139256


More information about the cfe-commits mailing list