Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
Checks: 'bugprone-use-after-move,bugprone-dangling-handle,performance-move-const-arg,performance-unnecessary-copy-initialization,-clang-diagnostic-unused-command-line-argument'
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This is a good initial set of checks. To further improve code quality, consider enabling more check groups. clang-tidy offers many useful checks that can catch subtle bugs and performance issues. For example, you could enable broader sets of checks like bugprone-*, performance-*, and modernize-*, and then explicitly disable any specific checks that are too noisy for this project. This iterative approach will help maximize the benefits of static analysis.

WarningsAsErrors: ''
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To ensure clang-tidy behaves consistently for all developers and in CI, it's best to configure it to treat warnings as errors directly in this file. This should be done in conjunction with removing the --warnings-as-errors='*' flag from the Makefile command.

WarningsAsErrors: '*'

HeaderFilterRegex: '.*'
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,32 @@ jobs:
exit 1
fi
shell: bash

clang-tidy:
name: Run clang-tidy checks
runs-on: ubuntu-22.04
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v4

- name: Install clang-tidy 20
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 20
sudo apt-get install -y clang-tidy-20

- name: Install dependencies
run: |
sudo apt update -y
sudo bash -x dependencies.sh -y

- name: Generate compile_commands.json
run: |
mkdir build
cd build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..

- name: Run clang-tidy
run: make tidy
shell: bash
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: tidy
tidy:
@find mooncake-transfer-engine -name "*.cpp" | head -5 | xargs -P $(shell nproc) -I {} clang-tidy-20 -p build --warnings-as-errors='*' {}
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The use of head -5 here severely limits the scope of the static analysis, as it will only check the first 5 .cpp files it finds. This undermines the goal of having a comprehensive static analysis check in CI. Please remove head -5 to ensure all source files are checked.

Additionally, it's better practice to configure warnings-as-errors in the .clang-tidy file rather than as a command-line argument. This ensures consistent behavior for developers running the tool locally. I've added a suggestion on the .clang-tidy file to move this setting.

	@find mooncake-transfer-engine -name "*.cpp" | xargs -P $(shell nproc) -I {} clang-tidy-20 -p build {}

4 changes: 2 additions & 2 deletions mooncake-transfer-engine/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ class RWSpinlock {
const static int64_t kExclusiveLock = INT64_MIN / 2;

std::atomic<int64_t> lock_;
uint64_t padding_[15];
[[maybe_unused]] uint64_t padding_[15];
};

class TicketLock {
Expand All @@ -501,7 +501,7 @@ class TicketLock {
private:
std::atomic<int> next_ticket_;
std::atomic<int> now_serving_;
uint64_t padding_[14];
[[maybe_unused]] uint64_t padding_[14];
};

class SimpleRandom {
Expand Down
2 changes: 1 addition & 1 deletion mooncake-transfer-engine/include/common/base/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ inline Status::Status(Status&& s) : Status() { *this = std::move(s); }

inline Status& Status::operator=(Status&& s) {
if (this != &s) {
code_ = std::move(s.code_);
code_ = s.code_;
s.code_ = Code::kOk;
delete[] message_;
message_ = nullptr;
Expand Down
4 changes: 1 addition & 3 deletions mooncake-transfer-engine/tests/transfer_metadata_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class TransferMetadataTest : public ::testing::Test {
const char* env = std::getenv("MC_METADATA_SERVER");
if (env)
metadata_server = env;
else
metadata_server = metadata_server;
LOG(INFO) << "metadata_server: " << metadata_server;

env = std::getenv("MC_LOCAL_SERVER_NAME");
Expand Down Expand Up @@ -116,7 +114,7 @@ TEST_F(TransferMetadataTest, RpcMetaEntryTest) {
int re = metadata_client->addRpcMetaEntry("test_server", desc);
ASSERT_EQ(re, 0);
TransferMetadata::RpcMetaDesc desc1;
re = metadata_client->getRpcMetaEntry("test_server", desc1);
ASSERT_EQ(metadata_client->getRpcMetaEntry("test_server", desc1), 0);
ASSERT_EQ(desc.ip_or_host_name, desc1.ip_or_host_name);
ASSERT_EQ(desc.rpc_port, desc1.rpc_port);
re = metadata_client->removeRpcMetaEntry("test_server");
Expand Down
Loading