Finish making clang-tidy (mostly) work (again) and run -fix (#2312)

This does some more work to the run_clang_tidy.py wrapper script, and runs an example pass.

"again" because it's really the proto fuzzer changes that broke it, it had been working before.

"mostly" because there's still an issue within the proto fuzzer that it can't find "port/protobuf.h", i.e. https://github.com/google/libprotobuf-mutator/tree/master/port, but I'm still hesitant to add an include path there.
This commit is contained in:
Jon Ross-Perkins
2022-10-18 15:48:17 -07:00
committed by GitHub
parent 561e45033e
commit 4d522c8e90
31 changed files with 176 additions and 141 deletions
+17 -12
View File
@@ -22,10 +22,14 @@ namespace Carbon {
namespace Internal {
struct Empty {
friend bool operator==(Empty, Empty) { return true; }
friend auto operator==(Empty /*unused*/, Empty /*unused*/) -> bool {
return true;
}
};
struct Tombstone {
friend bool operator==(Tombstone, Tombstone) { return true; }
friend auto operator==(Tombstone /*unused*/, Tombstone /*unused*/) -> bool {
return true;
}
};
// Type alias for the variant representing any of the values that can be
@@ -36,16 +40,16 @@ using KeyType =
// `KeyInfo` is used as a template argument to `llvm::DenseMap` to specify how
// to equality-compare and hash `KeyType`.
struct KeyInfo {
static bool isEqual(const KeyType& lhs, const KeyType& rhs) {
static auto isEqual(const KeyType& lhs, const KeyType& rhs) -> bool {
return lhs == rhs;
}
static unsigned getHashValue(const KeyType& x) {
static auto getHashValue(const KeyType& x) -> unsigned {
return std::visit(
[](auto x) -> unsigned {
using type = std::decay_t<decltype(x)>;
if constexpr (std::is_same_v<type, clang::DynTypedNode>) {
using Type = std::decay_t<decltype(x)>;
if constexpr (std::is_same_v<Type, clang::DynTypedNode>) {
return clang::DynTypedNode::DenseMapInfo::getHashValue(x);
} else if constexpr (std::is_same_v<type, clang::TypeLoc>) {
} else if constexpr (std::is_same_v<Type, clang::TypeLoc>) {
// TODO: Improve this.
return reinterpret_cast<uintptr_t>(x.getTypePtr());
} else {
@@ -55,8 +59,8 @@ struct KeyInfo {
x);
}
static KeyType getEmptyKey() { return Empty{}; }
static KeyType getTombstoneKey() { return Tombstone{}; }
static auto getEmptyKey() -> KeyType { return Empty{}; }
static auto getTombstoneKey() -> KeyType { return Tombstone{}; }
};
} // namespace Internal
@@ -177,7 +181,7 @@ class MigrationConsumer : public clang::ASTConsumer {
public:
explicit MigrationConsumer(std::string& result,
std::pair<size_t, size_t> output_range)
: result_(result), output_range_(output_range) {}
: result_(result), output_range_(std::move(output_range)) {}
auto HandleTranslationUnit(clang::ASTContext& context) -> void override;
@@ -199,11 +203,12 @@ class MigrationAction : public clang::ASTFrontendAction {
// `output_range.second` will be written.
explicit MigrationAction(std::string& result,
std::pair<size_t, size_t> output_range)
: result_(result), output_range_(output_range) {}
: result_(result), output_range_(std::move(output_range)) {}
// Returns a `std::unique_ptr` to a `clang::MigrationConsumer` which populates
// the output `result`.
auto CreateASTConsumer(clang::CompilerInstance&, llvm::StringRef)
auto CreateASTConsumer(clang::CompilerInstance& /*CI*/,
llvm::StringRef /*InFile*/)
-> std::unique_ptr<clang::ASTConsumer> override {
return std::make_unique<MigrationConsumer>(result_, output_range_);
}