Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,11 @@ class CheckerManager {
StringRef OptionName,
StringRef ExpectedValueDesc) const;

using CheckerRef = CheckerBase *;
using CheckerTag = const void *;
using CheckerDtor = CheckerFn<void ()>;

//===----------------------------------------------------------------------===//
// Checker registration.
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
// Checker registration.
//===----------------------------------------------------------------------===//
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indentation was added automatically by git-clang-format 🙄

There are several similar section markers in this source file -- should I indent all of them for consistency, or is there a reasonable way to silence the automatic formatting?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do:

// clang-format off
    void    unformatted_code  ;
// clang-format on

But I don't think that is worth it here. I am OK with just changing this code to make clang-format happy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could as well just drop this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll indent this comment and the other analogous headings to satisfy git-clang-format. I don't want to remove them because I feel that visible headers like this are very useful when I want to quickly understand the architecture of a large cumbersome class.


/// Used to register checkers.
/// All arguments are automatically passed through to the checker
Expand All @@ -201,24 +199,24 @@ class CheckerManager {
template <typename CHECKER, typename... AT>
CHECKER *registerChecker(AT &&... Args) {
CheckerTag tag = getTag<CHECKER>();
CheckerRef &ref = CheckerTags[tag];
assert(!ref && "Checker already registered, use getChecker!");

CHECKER *checker = new CHECKER(std::forward<AT>(Args)...);
checker->Name = CurrentCheckerName;
CheckerDtors.push_back(CheckerDtor(checker, destruct<CHECKER>));
CHECKER::_register(checker, *this);
ref = checker;
return checker;
std::unique_ptr<CheckerBase> &Ref = CheckerTags[tag];
assert(!Ref && "Checker already registered, use getChecker!");

std::unique_ptr<CHECKER> Checker =
std::make_unique<CHECKER>(std::forward<AT>(Args)...);
Checker->Name = CurrentCheckerName;
CHECKER::_register(Checker.get(), *this);
Ref = std::move(Checker);
return static_cast<CHECKER *>(Ref.get());
}

template <typename CHECKER>
CHECKER *getChecker() {
CheckerTag tag = getTag<CHECKER>();
assert(CheckerTags.count(tag) != 0 &&
"Requested checker is not registered! Maybe you should add it as a "
"dependency in Checkers.td?");
return static_cast<CHECKER *>(CheckerTags[tag]);
CheckerTag Tag = getTag<CHECKER>();
std::unique_ptr<CheckerBase> &Ref = CheckerTags[Tag];
assert(Ref && "Requested checker is not registered! Maybe you should add it"
" as a dependency in Checkers.td?");
return static_cast<CHECKER *>(Ref.get());
}

template <typename CHECKER> bool isRegisteredChecker() {
Expand Down Expand Up @@ -622,9 +620,7 @@ class CheckerManager {
template <typename T>
static void *getTag() { static int tag; return &tag; }

llvm::DenseMap<CheckerTag, CheckerRef> CheckerTags;

std::vector<CheckerDtor> CheckerDtors;
llvm::DenseMap<CheckerTag, std::unique_ptr<CheckerBase>> CheckerTags;

struct DeclCheckerInfo {
CheckDeclFunc CheckFn;
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/StaticAnalyzer/Frontend/CreateCheckerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//
//===----------------------------------------------------------------------===//

#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
#include <memory>
Expand Down Expand Up @@ -41,8 +42,8 @@ CheckerManager::CheckerManager(AnalyzerOptions &AOptions,
}

CheckerManager::~CheckerManager() {
for (const auto &CheckerDtor : CheckerDtors)
CheckerDtor();
// This is declared here to ensure that the destructors of `CheckerBase` and
// `CheckerRegistryData` are available.
}

} // namespace ento
Expand Down