[PATCH] D75842: [Analyzer] Bugfix for CheckerRegistry
Balogh, Ádám via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 17 12:57:07 PDT 2020
baloghadamsoftware updated this revision to Diff 250860.
baloghadamsoftware added a comment.
Herald added a subscriber: ASDenysPetrov.
Updated according to the comments.
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.250860.patch
Type: text/x-patch
Size: 3322 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200317/cd3ec2cc/attachment.bin>
More information about the cfe-commits
mailing list