Skip to content
Merged
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
55 changes: 55 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Checks: >
readability-identifier-naming,
readability-implicit-bool-conversion,
misc-const-correctness,
-clang-diagnostic-error

CheckOptions:
- key: readability-identifier-naming.ClassCase
value: lower_case
- key: readability-identifier-naming.StructCase
value: lower_case

- key: readability-identifier-naming.FunctionCase
value: lower_case
- key: readability-identifier-naming.MethodCase
value: lower_case
- key: readability-identifier-naming.MethodIgnoredRegexp
value: '^[A-Z][A-Z0-9_]*$'

- key: readability-identifier-naming.VariableCase
value: lower_case
- key: readability-identifier-naming.VariableIgnoredRegexp
value: '^[A-Z][A-Z0-9_]*$'
- key: readability-identifier-naming.LocalVariableCase
value: lower_case
- key: readability-identifier-naming.ParameterCase
value: lower_case

- key: readability-identifier-naming.MemberCase
value: lower_case
- key: readability-identifier-naming.MemberIgnoredRegexp
value: '^([A-Z][A-Z0-9_]*|[a-z][a-z0-9_]*_)$'
- key: readability-identifier-naming.PrivateMemberSuffix
value: '_'
- key: readability-identifier-naming.ProtectedMemberSuffix
value: '_'
- key: readability-identifier-naming.ConstantMemberIgnoredRegexp
value: '^[A-Z][A-Z0-9_]*$'

- key: readability-identifier-naming.EnumConstantCase
value: UPPER_CASE

- key: readability-identifier-naming.EnumCase
value: lower_case

- key: readability-identifier-naming.TemplateParameterCase
value: CamelCase

- key: readability-identifier-naming.NamespaceCase
value: lower_case

- key: readability-identifier-naming.TypeAliasCase
value: lower_case
- key: readability-identifier-naming.TypeAliasIgnoredRegexp
value: '^[A-Z]$'
19 changes: 18 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,27 @@ jobs:
find include tests -name "*.h" -o -name "*.cpp" | \
xargs clang-format --dry-run --Werror

clang-tidy:
name: Clang Tidy
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
- name: Install clang-tidy-19
run: |
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-19 main" | sudo tee /etc/apt/sources.list.d/llvm.list
sudo apt-get update
sudo apt-get install -y clang-tidy-19
- name: Check formatting
run: |
find include -name "*.h" -o -name "*.cpp" | \
xargs -I{} clang-tidy-19 {} -- -x c++ -std=c++20 -I include -include cstdint -include cstddef

all-checks:
name: All Checks
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
needs: [unittests, clang-format]
needs: [unittests, clang-format, clang-tidy]
steps:
- run: echo "All checks passed"
4 changes: 2 additions & 2 deletions include/pvm/engine/architecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ namespace ngu::pvm {
std::uint64_t rng_state{entropy};
for (std::size_t i{count - 1}; i > 0; i--) {
rng_state = lcg_next(rng_state);
std::size_t j{rng_state % (i + 1)};
std::uint8_t tmp{arr[i]};
std::size_t const j{rng_state % (i + 1)};
std::uint8_t const tmp{arr[i]};
arr[i] = arr[j];
arr[j] = tmp;
}
Expand Down
12 changes: 6 additions & 6 deletions include/pvm/engine/instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ namespace ngu::pvm {
auto const val = ctx->get_reg(insn.destination());
auto shift = insn.has_immediate() ? insn.immediate() : ctx->get_reg(insn.source());
shift &= 63;
ctx->set_reg(insn.destination(), (val << shift) | (val >> (64 - shift)));
ctx->set_reg(insn.destination(), shift != 0 ? (val << shift) | (val >> (64 - shift)) : val);
}
};

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

Expand Down Expand Up @@ -166,7 +166,7 @@ namespace ngu::pvm {

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

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

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

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

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

if (pos >= insn_entries.size()) {
Expand Down
Loading