diff options
author | Kristof Umann <kristof.umann@ericsson.com> | 2019-04-19 11:01:35 +0000 |
---|---|---|
committer | Kristof Umann <kristof.umann@ericsson.com> | 2019-04-19 11:01:35 +0000 |
commit | cd3f147439724c73991f667f435bef03508749e4 (patch) | |
tree | b39b21e194e2b459cc644d49101bd1f0473e9677 /clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp | |
parent | 99f641ccadcab1e5b98f6ad09a9344855cdf287a (diff) | |
download | bcm5719-llvm-cd3f147439724c73991f667f435bef03508749e4.tar.gz bcm5719-llvm-cd3f147439724c73991f667f435bef03508749e4.zip |
[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
llvm-svn: 358750
Diffstat (limited to 'clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp index 3ee35b4aeea..8f1c87a92ee 100644 --- a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp +++ b/clang/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 { |