Skip to content

Commit 448a269

Browse files
chore: add clang-tidy, update ci
1 parent d280e50 commit 448a269

File tree

4 files changed

+81
-9
lines changed

4 files changed

+81
-9
lines changed

.clang-tidy

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Checks: >
2+
readability-identifier-naming,
3+
readability-implicit-bool-conversion,
4+
misc-const-correctness,
5+
-clang-diagnostic-error
6+
7+
CheckOptions:
8+
- key: readability-identifier-naming.ClassCase
9+
value: lower_case
10+
- key: readability-identifier-naming.StructCase
11+
value: lower_case
12+
13+
- key: readability-identifier-naming.FunctionCase
14+
value: lower_case
15+
- key: readability-identifier-naming.MethodCase
16+
value: lower_case
17+
- key: readability-identifier-naming.MethodIgnoredRegexp
18+
value: '^[A-Z][A-Z0-9_]*$'
19+
20+
- key: readability-identifier-naming.VariableCase
21+
value: lower_case
22+
- key: readability-identifier-naming.VariableIgnoredRegexp
23+
value: '^[A-Z][A-Z0-9_]*$'
24+
- key: readability-identifier-naming.LocalVariableCase
25+
value: lower_case
26+
- key: readability-identifier-naming.ParameterCase
27+
value: lower_case
28+
29+
- key: readability-identifier-naming.MemberCase
30+
value: lower_case
31+
- key: readability-identifier-naming.MemberIgnoredRegexp
32+
value: '^([A-Z][A-Z0-9_]*|[a-z][a-z0-9_]*_)$'
33+
- key: readability-identifier-naming.PrivateMemberSuffix
34+
value: '_'
35+
- key: readability-identifier-naming.ProtectedMemberSuffix
36+
value: '_'
37+
- key: readability-identifier-naming.ConstantMemberIgnoredRegexp
38+
value: '^[A-Z][A-Z0-9_]*$'
39+
40+
- key: readability-identifier-naming.EnumConstantCase
41+
value: UPPER_CASE
42+
43+
- key: readability-identifier-naming.EnumCase
44+
value: lower_case
45+
46+
- key: readability-identifier-naming.TemplateParameterCase
47+
value: CamelCase
48+
49+
- key: readability-identifier-naming.NamespaceCase
50+
value: lower_case
51+
52+
- key: readability-identifier-naming.TypeAliasCase
53+
value: lower_case
54+
- key: readability-identifier-naming.TypeAliasIgnoredRegexp
55+
value: '^[A-Z]$'

.github/workflows/ci.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,27 @@ jobs:
118118
find include tests -name "*.h" -o -name "*.cpp" | \
119119
xargs clang-format --dry-run --Werror
120120
121+
clang-tidy:
122+
name: Clang Tidy
123+
runs-on: ubuntu-latest
124+
if: github.event_name == 'pull_request'
125+
steps:
126+
- uses: actions/checkout@v4
127+
- name: Install clang-tidy-19
128+
run: |
129+
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
130+
echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-19 main" | sudo tee /etc/apt/sources.list.d/llvm.list
131+
sudo apt-get update
132+
sudo apt-get install -y clang-tidy-19
133+
- name: Check formatting
134+
run: |
135+
find include -name "*.h" -o -name "*.cpp" | \
136+
xargs -I{} clang-tidy-19 {} -- -x c++ -std=c++20 -I include -include cstdint -include cstddef
137+
121138
all-checks:
122139
name: All Checks
123140
runs-on: ubuntu-latest
124141
if: github.event_name == 'pull_request'
125-
needs: [unittests, clang-format]
142+
needs: [unittests, clang-format, clang-tidy]
126143
steps:
127144
- run: echo "All checks passed"

include/pvm/engine/architecture.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ namespace ngu::pvm {
3939
std::uint64_t rng_state{entropy};
4040
for (std::size_t i{count - 1}; i > 0; i--) {
4141
rng_state = lcg_next(rng_state);
42-
std::size_t j{rng_state % (i + 1)};
43-
std::uint8_t tmp{arr[i]};
42+
std::size_t const j{rng_state % (i + 1)};
43+
std::uint8_t const tmp{arr[i]};
4444
arr[i] = arr[j];
4545
arr[j] = tmp;
4646
}

include/pvm/engine/instructions.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ namespace ngu::pvm {
108108
auto const val = ctx->get_reg(insn.destination());
109109
auto shift = insn.has_immediate() ? insn.immediate() : ctx->get_reg(insn.source());
110110
shift &= 63;
111-
ctx->set_reg(insn.destination(), (val << shift) | (val >> (64 - shift)));
111+
ctx->set_reg(insn.destination(), shift != 0 ? (val << shift) | (val >> (64 - shift)) : val);
112112
}
113113
};
114114

@@ -117,7 +117,7 @@ namespace ngu::pvm {
117117
auto const val = ctx->get_reg(insn.destination());
118118
auto shift = insn.has_immediate() ? insn.immediate() : ctx->get_reg(insn.source());
119119
shift &= 63;
120-
ctx->set_reg(insn.destination(), (val >> shift) | (val << (64 - shift)));
120+
ctx->set_reg(insn.destination(), shift != 0 ? (val >> shift) | (val << (64 - shift)) : val);
121121
}
122122
};
123123

@@ -166,7 +166,7 @@ namespace ngu::pvm {
166166

167167
struct jne_base {
168168
PVM_FORCEINLINE static void impl(context* ctx, const insn_view& insn) {
169-
if (!(ctx->get_flags() & 1)) {
169+
if ((ctx->get_flags() & 1) == 0u) {
170170
auto const offset = insn.has_immediate() ? insn.immediate() : ctx->get_reg(insn.source());
171171
ctx->jump(ctx->get_pc() + insn.size() + offset);
172172
}
@@ -175,7 +175,7 @@ namespace ngu::pvm {
175175

176176
struct je_base {
177177
PVM_FORCEINLINE static void impl(context* ctx, const insn_view& insn) {
178-
if (ctx->get_flags() & 1) {
178+
if ((ctx->get_flags() & 1) != 0u) {
179179
auto const offset = insn.has_immediate() ? insn.immediate() : ctx->get_reg(insn.source());
180180
ctx->jump(ctx->get_pc() + insn.size() + offset);
181181
}
@@ -184,7 +184,7 @@ namespace ngu::pvm {
184184

185185
struct jnei_base {
186186
PVM_FORCEINLINE static void impl(context* ctx, const insn_view& insn, const insn_stream_rt& insn_entries) {
187-
if (!(ctx->get_flags() & 1)) {
187+
if ((ctx->get_flags() & 1) == 0u) {
188188
auto const pos = insn.has_immediate() ? insn.immediate() : ctx->get_reg(insn.source());
189189

190190
if (pos >= insn_entries.size()) {
@@ -198,7 +198,7 @@ namespace ngu::pvm {
198198

199199
struct jei_base {
200200
PVM_FORCEINLINE static void impl(context* ctx, const insn_view& insn, const insn_stream_rt& insn_entries) {
201-
if (ctx->get_flags() & 1) {
201+
if ((ctx->get_flags() & 1) != 0u) {
202202
auto const pos = insn.has_immediate() ? insn.immediate() : ctx->get_reg(insn.source());
203203

204204
if (pos >= insn_entries.size()) {

0 commit comments

Comments
 (0)