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
+2 -2
View File
@@ -37,7 +37,7 @@ class OutputSegment {
// instead. However, most other types we intend to support as they become
// necessary.
template <typename T>
static constexpr bool IsSupportedClangASTNodeType() {
static constexpr auto IsSupportedClangASTNodeType() -> bool {
return std::is_convertible_v<T*, clang::Stmt*> ||
std::is_convertible_v<T*, clang::Decl*>;
}
@@ -62,7 +62,7 @@ class OutputSegment {
friend struct OutputWriter;
template <typename T>
T& AssertNotNull(T* ptr) {
auto AssertNotNull(T* ptr) -> T& {
CARBON_CHECK(ptr != nullptr);
return *ptr;
}
+5 -5
View File
@@ -16,18 +16,18 @@ auto OutputWriter::Write(clang::SourceLocation loc,
const OutputSegment& segment) const -> bool {
return std::visit(
[&](auto& content) {
using type = std::decay_t<decltype(content)>;
using Type = std::decay_t<decltype(content)>;
auto [begin, end] = bounds;
if constexpr (std::is_same_v<type, std::string>) {
if constexpr (std::is_same_v<Type, std::string>) {
auto begin_offset = source_manager.getDecomposedLoc(loc).second;
// Append the string replacement if the node being replaced falls
// within `bounds`.
if (begin <= begin_offset && begin_offset < end) {
output.append(content);
}
} else if constexpr (std::is_same_v<type, clang::DynTypedNode> ||
std::is_same_v<type, clang::TypeLoc>) {
} else if constexpr (std::is_same_v<Type, clang::DynTypedNode> ||
std::is_same_v<Type, clang::TypeLoc>) {
auto content_loc = content.getSourceRange().getBegin();
auto begin_offset =
source_manager.getDecomposedLoc(content_loc).second;
@@ -54,7 +54,7 @@ auto OutputWriter::Write(clang::SourceLocation loc,
}
}
} else {
static_assert(std::is_void_v<type>,
static_assert(std::is_void_v<Type>,
"Failed to handle a case in the `std::variant`.");
}
return true;
+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_);
}
+5 -3
View File
@@ -19,7 +19,7 @@ namespace {
// an annotated range.
class Annotations {
public:
Annotations(llvm::StringRef annotated_source) {
explicit Annotations(llvm::StringRef annotated_source) {
size_t index = annotated_source.find("$[[");
if (index == llvm::StringRef::npos) {
source_code_ = std::string(annotated_source);
@@ -39,11 +39,13 @@ class Annotations {
}
// Returns a view into the unannotated source.
llvm::StringRef source() const { return source_code_; }
auto source() const -> llvm::StringRef { return source_code_; }
// Returns the offsets in the file representing the annotated range if they
// exist and `{0, std::numeric_limits<size_t>::max()}` otherwise.
std::pair<size_t, size_t> range() const { return std::pair(start_, end_); }
auto range() const -> std::pair<size_t, size_t> {
return std::pair(start_, end_);
}
private:
std::string source_code_;