summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristof Umann <kristof.umann@ericsson.com>2019-04-19 11:01:35 +0000
committerKristof Umann <kristof.umann@ericsson.com>2019-04-19 11:01:35 +0000
commitdcf9f6429ba12fd17f772b9ae08e454c79bed73b (patch)
tree05b4a38c9afbc233ef459de255a650aace35aac2
parentfefa4bbbd61cffada3e1301f46aae09e87a21178 (diff)
[analyzer] Fix an assertion failure if plugins added dependencies
Ideally, there is no reason behind not being able to depend on checkers that come from a different plugin (or on builtin checkers) -- however, this is only possible if all checkers are added to the registry before resolving checker dependencies. Since I used a binary search in my addDependency method, this also resulted in an assertion failure (due to CheckerRegistry::Checkers not being sorted), since the function used by plugins to register their checkers (clang_registerCheckers) calls addDependency. This patch resolves this issue by only noting which dependencies have to established when addDependency is called, and resolves them at a later stage when no more checkers are added to the registry, by which point CheckerRegistry::Checkers is already sorted. Differential Revision: https://reviews.llvm.org/D59461 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358750 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h6
-rw-r--r--lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp30
-rw-r--r--test/Analysis/checker-dependencies.c17
3 files changed, 43 insertions, 10 deletions
diff --git a/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h b/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
index ab8fff0ce7..052ef66e60 100644
--- a/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
+++ b/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
@@ -195,6 +195,12 @@ private:
CheckerInfoList Checkers;
llvm::StringMap<size_t> PackageSizes;
+ /// Contains all (Dependendent checker, Dependency) pairs. We need this, as
+ /// we'll resolve dependencies after all checkers were added first.
+ llvm::SmallVector<std::pair<StringRef, StringRef>, 0> Dependencies;
+
+ void resolveDependencies();
+
DiagnosticsEngine &Diags;
AnalyzerOptions &AnOpts;
const LangOptions &LangOpts;
diff --git a/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp b/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
index 3ee35b4aee..8f1c87a92e 100644
--- a/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ b/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -177,6 +177,8 @@ CheckerRegistry::CheckerRegistry(
#undef CHECKER_DEPENDENCY
#undef GET_CHECKER_DEPENDENCIES
+ resolveDependencies();
+
// Parse '-analyzer-checker' and '-analyzer-disable-checker' options from the
// command line.
for (const std::pair<std::string, bool> &Opt : AnOpts.CheckersControlList) {
@@ -278,18 +280,26 @@ void CheckerRegistry::addChecker(InitializationFunction Rfn,
}
}
-void CheckerRegistry::addDependency(StringRef FullName, StringRef Dependency) {
- auto CheckerIt = binaryFind(Checkers, FullName);
- assert(CheckerIt != Checkers.end() && CheckerIt->FullName == FullName &&
- "Failed to find the checker while attempting to set up its "
- "dependencies!");
+void CheckerRegistry::resolveDependencies() {
+ for (const std::pair<StringRef, StringRef> &Entry : Dependencies) {
+ auto CheckerIt = binaryFind(Checkers, Entry.first);
+ assert(CheckerIt != Checkers.end() && CheckerIt->FullName == Entry.first &&
+ "Failed to find the checker while attempting to set up its "
+ "dependencies!");
- auto DependencyIt = binaryFind(Checkers, Dependency);
- assert(DependencyIt != Checkers.end() &&
- DependencyIt->FullName == Dependency &&
- "Failed to find the dependency of a checker!");
+ auto DependencyIt = binaryFind(Checkers, Entry.second);
+ assert(DependencyIt != Checkers.end() &&
+ DependencyIt->FullName == Entry.second &&
+ "Failed to find the dependency of a checker!");
+
+ CheckerIt->Dependencies.emplace_back(&*DependencyIt);
+ }
- CheckerIt->Dependencies.emplace_back(&*DependencyIt);
+ Dependencies.clear();
+}
+
+void CheckerRegistry::addDependency(StringRef FullName, StringRef Dependency) {
+ Dependencies.emplace_back(FullName, Dependency);
}
void CheckerRegistry::initializeManager(CheckerManager &CheckerMgr) const {
diff --git a/test/Analysis/checker-dependencies.c b/test/Analysis/checker-dependencies.c
index efb636db22..6c8583adb3 100644
--- a/test/Analysis/checker-dependencies.c
+++ b/test/Analysis/checker-dependencies.c
@@ -1,3 +1,20 @@
// RUN: %clang_analyze_cc1 %s \
// RUN: -analyzer-checker=core \
// RUN: -analyzer-checker=nullability.NullReturnedFromNonnull
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN: -analyzer-checker=osx.cocoa.RetainCount \
+// RUN: -analyzer-list-enabled-checkers \
+// RUN: 2>&1 | FileCheck %s -check-prefix=CHECK-IMPLICITLY-ENABLED
+
+// CHECK-IMPLICITLY-ENABLED: osx.cocoa.RetainCountBase
+// CHECK-IMPLICITLY-ENABLED: osx.cocoa.RetainCount
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN: -analyzer-checker=osx.cocoa.RetainCount \
+// RUN: -analyzer-disable-checker=osx.cocoa.RetainCountBase \
+// RUN: -analyzer-list-enabled-checkers \
+// RUN: 2>&1 | FileCheck %s -check-prefix=CHECK-IMPLICITLY-DISABLED
+
+// CHECK-IMPLICITLY-DISABLED-NOT: osx.cocoa.RetainCountBase
+// CHECK-IMPLICITLY-DISABLED-NOT: osx.cocoa.RetainCount