[PATCH] D75842: [Analyzer] Bugfix for CheckerRegistry

Balogh, Ádám via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 19 08:38:03 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG6cff2e9f7884: [Analyzer] Bugfix for CheckerRegistry (authored by baloghadamsoftware).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75842/new/

https://reviews.llvm.org/D75842

Files:
  clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
  clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp


Index: clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
===================================================================
--- clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
+++ clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
@@ -81,6 +81,66 @@
       runCheckerOnCode<addLocIncDecChecker>("void f() { int *p; (*p)++; }"));
 }
 
+//===----------------------------------------------------------------------===//
+// Unsatisfied checker dependency
+//===----------------------------------------------------------------------===//
+
+class PrerequisiteChecker : public Checker<check::ASTCodeBody> {
+public:
+  void checkASTCodeBody(const Decl *D, AnalysisManager &Mgr,
+                        BugReporter &BR) const {
+    BR.EmitBasicReport(D, this, "Prerequisite", categories::LogicError,
+                       "This is the prerequisite checker",
+                       PathDiagnosticLocation(D, Mgr.getSourceManager()), {});
+  }
+};
+
+void registerPrerequisiteChecker(CheckerManager &mgr) {
+  mgr.registerChecker<PrerequisiteChecker>();
+}
+
+bool shouldRegisterPrerequisiteChecker(const LangOptions &LO) {
+  return false;
+}
+
+class DependentChecker : public Checker<check::ASTCodeBody> {
+public:
+  void checkASTCodeBody(const Decl *D, AnalysisManager &Mgr,
+                        BugReporter &BR) const {
+    BR.EmitBasicReport(D, this, "Dependent", categories::LogicError,
+                       "This is the Dependent Checker",
+                       PathDiagnosticLocation(D, Mgr.getSourceManager()), {});
+  }
+};
+
+void registerDependentChecker(CheckerManager &mgr) {
+  mgr.registerChecker<DependentChecker>();
+}
+
+bool shouldRegisterDependentChecker(const LangOptions &LO) {
+  return true;
+}
+
+void addDependentChecker(AnalysisASTConsumer &AnalysisConsumer,
+                         AnalyzerOptions &AnOpts) {
+  AnOpts.CheckersAndPackages = {{"custom.Dependent", true}};
+  AnalysisConsumer.AddCheckerRegistrationFn([](CheckerRegistry &Registry) {
+     Registry.addChecker(registerPrerequisiteChecker,
+                         shouldRegisterPrerequisiteChecker,
+                         "custom.Prerequisite", "Description", "", false);
+     Registry.addChecker(registerDependentChecker,
+                         shouldRegisterDependentChecker,
+                         "custom.Dependent", "Description", "", false);
+     Registry.addDependency("custom.Dependent", "custom.Prerequisite");
+    });
+}
+
+TEST(RegisterDependentCheckers, RegisterChecker) {
+  std::string Diags;
+  EXPECT_TRUE(runCheckerOnCode<addDependentChecker>("void f() {;}", Diags));
+  EXPECT_EQ(Diags, "");
+}
+
 } // namespace
 } // namespace ento
 } // namespace clang
Index: clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
===================================================================
--- clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
+++ clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
@@ -167,7 +167,7 @@
     }
 
     bool isDisabled(const LangOptions &LO) const {
-      return State == StateFromCmdLine::State_Disabled && ShouldRegister(LO);
+      return State == StateFromCmdLine::State_Disabled || !ShouldRegister(LO);
     }
 
     // Since each checker must have a different full name, we can identify


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75842.251394.patch
Type: text/x-patch
Size: 3322 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200319/369f79c2/attachment.bin>


More information about the cfe-commits mailing list