diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index d5bff766a..4495ebc9e 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -11,4 +11,7 @@ jobs: - name: Check out repo uses: actions/checkout@v3 - name: Run clang-format - uses: jidicula/clang-format-action@4.11.0 \ No newline at end of file + uses: jidicula/clang-format-action@v4.11.0 + with: + exclude-regex: (libspirv|3rdparty) + clang-format-version: 16 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index cece7df7f..b923b394a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,14 +12,10 @@ jobs: uses: ZedThree/clang-tidy-review@v0.13.1 id: review with: + clang_tidy_version: 15 apt_packages: libunwind-dev, libglfw3-dev, libvulkan-dev, vulkan-validationlayers-dev, spirv-tools cmake_command: cmake . -DCMAKE_EXPORT_COMPILE_COMMANDS=on - - # Uploads an artefact containing clang_fixes.json + split_workflow: true - name: Upload review uses: ZedThree/clang-tidy-review/upload@v0.13.1 - id: upload-review - - # If there are any comments, fail the check - - if: steps.review.outputs.total_comments > 0 - run: exit 1 \ No newline at end of file + id: upload-review \ No newline at end of file diff --git a/.github/workflows/tidy-comments.yml b/.github/workflows/tidy-comments.yml new file mode 100644 index 000000000..45e69dbcc --- /dev/null +++ b/.github/workflows/tidy-comments.yml @@ -0,0 +1,13 @@ +name: Post clang-tidy review comments +on: + workflow_run: + workflows: ["Linting"] + types: + - completed +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: ZedThree/clang-tidy-review/post@v0.12.0 + with: + lgtm_comment_body: "No linting issues found!" \ No newline at end of file diff --git a/hw/amdgpu/lib/libspirv/include/spirv/spirv-builder.hpp b/hw/amdgpu/lib/libspirv/include/spirv/spirv-builder.hpp index ae9cfc80f..3f332d83d 100644 --- a/hw/amdgpu/lib/libspirv/include/spirv/spirv-builder.hpp +++ b/hw/amdgpu/lib/libspirv/include/spirv/spirv-builder.hpp @@ -71,8 +71,8 @@ struct ImageValue : Value {}; struct SampledImageValue : Value {}; template -requires(std::is_base_of_v) struct ConstantValue : T { -}; + requires(std::is_base_of_v) +struct ConstantValue : T {}; struct AnyConstantValue : Value { AnyConstantValue() = default; @@ -95,28 +95,28 @@ struct AnyConstantValue : Value { }; template -requires(std::is_base_of_v) struct VectorOfType : VectorType { -}; + requires(std::is_base_of_v) +struct VectorOfType : VectorType {}; template -requires(std::is_base_of_v) struct ArrayOfType : ArrayType { -}; + requires(std::is_base_of_v) +struct ArrayOfType : ArrayType {}; template -requires(std::is_base_of_v) struct VectorOfValue : VectorValue { -}; + requires(std::is_base_of_v) +struct VectorOfValue : VectorValue {}; template -requires(std::is_base_of_v) struct ArrayOfValue : ArrayValue { -}; + requires(std::is_base_of_v) +struct ArrayOfValue : ArrayValue {}; template -requires(std::is_base_of_v) struct PointerToType : PointerType { -}; + requires(std::is_base_of_v) +struct PointerToType : PointerType {}; template -requires(std::is_base_of_v) struct PointerToValue : PointerValue { -}; + requires(std::is_base_of_v) +struct PointerToValue : PointerValue {}; struct StructPointerValue : Value {}; @@ -125,21 +125,45 @@ struct VariableValue : PointerValue {}; namespace detail { template struct TypeToValueImpl; -template <> struct TypeToValueImpl { using type = Value; }; -template <> struct TypeToValueImpl { using type = BoolValue; }; -template <> struct TypeToValueImpl { using type = IntValue; }; -template <> struct TypeToValueImpl { using type = SIntValue; }; -template <> struct TypeToValueImpl { using type = UIntValue; }; -template <> struct TypeToValueImpl { using type = FloatValue; }; -template <> struct TypeToValueImpl { using type = StructValue; }; -template <> struct TypeToValueImpl { using type = PointerValue; }; +template <> struct TypeToValueImpl { + using type = Value; +}; +template <> struct TypeToValueImpl { + using type = BoolValue; +}; +template <> struct TypeToValueImpl { + using type = IntValue; +}; +template <> struct TypeToValueImpl { + using type = SIntValue; +}; +template <> struct TypeToValueImpl { + using type = UIntValue; +}; +template <> struct TypeToValueImpl { + using type = FloatValue; +}; +template <> struct TypeToValueImpl { + using type = StructValue; +}; +template <> struct TypeToValueImpl { + using type = PointerValue; +}; template <> struct TypeToValueImpl { using type = PointerValue; }; -template <> struct TypeToValueImpl { using type = VectorValue; }; -template <> struct TypeToValueImpl { using type = ArrayValue; }; -template <> struct TypeToValueImpl { using type = SamplerValue; }; -template <> struct TypeToValueImpl { using type = ImageValue; }; +template <> struct TypeToValueImpl { + using type = VectorValue; +}; +template <> struct TypeToValueImpl { + using type = ArrayValue; +}; +template <> struct TypeToValueImpl { + using type = SamplerValue; +}; +template <> struct TypeToValueImpl { + using type = ImageValue; +}; template <> struct TypeToValueImpl { using type = SampledImageValue; }; @@ -160,7 +184,8 @@ template using TypeToValue = typename detail::TypeToValueImpl::type; template -requires(std::is_base_of_v) struct ScalarOrVectorOfValue : Value { + requires(std::is_base_of_v) +struct ScalarOrVectorOfValue : Value { ScalarOrVectorOfValue() = default; ScalarOrVectorOfValue(TypeToValue scalar) { id = scalar.id; } @@ -174,8 +199,8 @@ using ConstantInt = ConstantValue; using ConstantFloat = ConstantValue; template -requires(std::is_base_of_v &&std::is_base_of_v) ToT - cast(FromT from) { + requires(std::is_base_of_v && std::is_base_of_v) +ToT cast(FromT from) { ToT result; result.id = from.id; return result; @@ -252,7 +277,8 @@ struct IdGenerator { std::uint32_t bounds = 1; template - requires(std::is_base_of_v) T newId() { + requires(std::is_base_of_v) + T newId() { T result; result.id = bounds++; return result; @@ -518,8 +544,9 @@ public: // arithmetic template - requires(std::is_base_of_v) TypeToValue createInst( - spv::Op op, T resultType, std::span> operands) { + requires(std::is_base_of_v) + TypeToValue createInst(spv::Op op, T resultType, + std::span> operands) { auto region = bodyRegion.pushOp(op, 3 + operands.size()); auto id = newId>(); region.pushIdUse(resultType); @@ -556,142 +583,142 @@ public: } template - requires(std::is_same_v || - std::is_same_v, T>) - TypeToValue createSNegate(T resultType, TypeToValue operand) { + requires(std::is_same_v || + std::is_same_v, T>) + TypeToValue createSNegate(T resultType, TypeToValue operand) { return createInst(spv::Op::OpSNegate, resultType, std::array{operand}); } template - requires(std::is_same_v || - std::is_same_v, T>) - TypeToValue createFNegate(T resultType, TypeToValue operand) { + requires(std::is_same_v || + std::is_same_v, T>) + TypeToValue createFNegate(T resultType, TypeToValue operand) { return createInst(spv::Op::OpFNegate, resultType, std::array{operand}); } template - requires(std::is_same_v || std::is_base_of_v || - std::is_same_v, T> || - std::is_same_v, T> || - std::is_same_v, T>) - TypeToValue createIAdd(T resultType, TypeToValue operand1, - TypeToValue operand2) { + requires(std::is_same_v || std::is_base_of_v || + std::is_same_v, T> || + std::is_same_v, T> || + std::is_same_v, T>) + TypeToValue createIAdd(T resultType, TypeToValue operand1, + TypeToValue operand2) { return createInst(spv::Op::OpIAdd, resultType, std::array{operand1, operand2}); } template - requires(std::is_same_v || - std::is_same_v, T>) - TypeToValue createFAdd(T resultType, TypeToValue operand1, - TypeToValue operand2) { + requires(std::is_same_v || + std::is_same_v, T>) + TypeToValue createFAdd(T resultType, TypeToValue operand1, + TypeToValue operand2) { return createInst(spv::Op::OpFAdd, resultType, std::array{operand1, operand2}); } template - requires(std::is_same_v || std::is_base_of_v || - std::is_same_v, T> || - std::is_same_v, T> || - std::is_same_v, T>) - TypeToValue createISub(T resultType, TypeToValue operand1, - TypeToValue operand2) { + requires(std::is_same_v || std::is_base_of_v || + std::is_same_v, T> || + std::is_same_v, T> || + std::is_same_v, T>) + TypeToValue createISub(T resultType, TypeToValue operand1, + TypeToValue operand2) { return createInst(spv::Op::OpISub, resultType, std::array{operand1, operand2}); } template - requires(std::is_same_v || - std::is_same_v, T>) - TypeToValue createFSub(T resultType, TypeToValue operand1, - TypeToValue operand2) { + requires(std::is_same_v || + std::is_same_v, T>) + TypeToValue createFSub(T resultType, TypeToValue operand1, + TypeToValue operand2) { return createInst(spv::Op::OpFSub, resultType, std::array{operand1, operand2}); } template - requires(std::is_same_v || std::is_base_of_v || - std::is_same_v, T> || - std::is_same_v, T> || - std::is_same_v, T>) - TypeToValue createIMul(T resultType, TypeToValue operand1, - TypeToValue operand2) { + requires(std::is_same_v || std::is_base_of_v || + std::is_same_v, T> || + std::is_same_v, T> || + std::is_same_v, T>) + TypeToValue createIMul(T resultType, TypeToValue operand1, + TypeToValue operand2) { return createInst(spv::Op::OpIMul, resultType, std::array{operand1, operand2}); } template - requires(std::is_same_v || - std::is_same_v, T>) - TypeToValue createFMul(T resultType, TypeToValue operand1, - TypeToValue operand2) { + requires(std::is_same_v || + std::is_same_v, T>) + TypeToValue createFMul(T resultType, TypeToValue operand1, + TypeToValue operand2) { return createInst(spv::Op::OpFMul, resultType, std::array{operand1, operand2}); } template - requires(std::is_same_v || - std::is_same_v, T>) - TypeToValue createUDiv(T resultType, TypeToValue operand1, - TypeToValue operand2) { + requires(std::is_same_v || + std::is_same_v, T>) + TypeToValue createUDiv(T resultType, TypeToValue operand1, + TypeToValue operand2) { return createInst(spv::Op::OpUDiv, resultType, std::array{operand1, operand2}); } template - requires(std::is_same_v || - std::is_same_v, T>) - TypeToValue createSDiv(T resultType, TypeToValue operand1, - TypeToValue operand2) { + requires(std::is_same_v || + std::is_same_v, T>) + TypeToValue createSDiv(T resultType, TypeToValue operand1, + TypeToValue operand2) { return createInst(spv::Op::OpSDiv, resultType, std::array{operand1, operand2}); } template - requires(std::is_same_v || - std::is_same_v, T>) - TypeToValue createFDiv(T resultType, TypeToValue operand1, - TypeToValue operand2) { + requires(std::is_same_v || + std::is_same_v, T>) + TypeToValue createFDiv(T resultType, TypeToValue operand1, + TypeToValue operand2) { return createInst(spv::Op::OpFDiv, resultType, std::array{operand1, operand2}); } template - requires(std::is_same_v || - std::is_same_v, T>) - TypeToValue createUMod(T resultType, TypeToValue operand1, - TypeToValue operand2) { + requires(std::is_same_v || + std::is_same_v, T>) + TypeToValue createUMod(T resultType, TypeToValue operand1, + TypeToValue operand2) { return createInst(spv::Op::OpUMod, resultType, std::array{operand1, operand2}); } template - requires(std::is_same_v || - std::is_same_v, T>) - TypeToValue createSRem(T resultType, TypeToValue operand1, - TypeToValue operand2) { + requires(std::is_same_v || + std::is_same_v, T>) + TypeToValue createSRem(T resultType, TypeToValue operand1, + TypeToValue operand2) { return createInst(spv::Op::OpSRem, resultType, std::array{operand1, operand2}); } template - requires(std::is_same_v || - std::is_same_v, T>) - TypeToValue createSMod(T resultType, TypeToValue operand1, - TypeToValue operand2) { + requires(std::is_same_v || + std::is_same_v, T>) + TypeToValue createSMod(T resultType, TypeToValue operand1, + TypeToValue operand2) { return createInst(spv::Op::OpSMod, resultType, std::array{operand1, operand2}); } template - requires(std::is_same_v || - std::is_same_v, T>) - TypeToValue createFRem(T resultType, TypeToValue operand1, - TypeToValue operand2) { + requires(std::is_same_v || + std::is_same_v, T>) + TypeToValue createFRem(T resultType, TypeToValue operand1, + TypeToValue operand2) { return createInst(spv::Op::OpFRem, resultType, std::array{operand1, operand2}); } template - requires(std::is_same_v || - std::is_same_v, T>) - TypeToValue createFMod(T resultType, TypeToValue operand1, - TypeToValue operand2) { + requires(std::is_same_v || + std::is_same_v, T>) + TypeToValue createFMod(T resultType, TypeToValue operand1, + TypeToValue operand2) { return createInst(spv::Op::OpFMod, resultType, std::array{operand1, operand2}); } @@ -768,8 +795,9 @@ public: } template - requires(std::is_base_of_v) TypeToValue createPhi( - T resultType, std::span> values) { + requires(std::is_base_of_v) + TypeToValue createPhi(T resultType, + std::span> values) { return cast>( createPhi(static_cast(resultType), values)); } @@ -855,8 +883,8 @@ public: } template - requires(std::is_base_of_v) - TypeToValue createLoad(T resultType, PointerValue pointer) { + requires(std::is_base_of_v) + TypeToValue createLoad(T resultType, PointerValue pointer) { auto region = bodyRegion.pushOp(spv::Op::OpLoad, 4); auto id = newId>(); region.pushIdUse(resultType); @@ -1588,8 +1616,8 @@ public: : mIdGenerator(&idGenerator), capabilityRegion{1}, extensionRegion{1}, extInstRegion{4}, memoryModelRegion{3}, entryPointRegion{1}, executionModeRegion{1}, debugRegion{0}, annotationRegion{1}, - globalRegion{1}, functionDeclRegion{1}, functionRegion{ - expInstructionsCount} {} + globalRegion{1}, functionDeclRegion{1}, + functionRegion{expInstructionsCount} {} SpirvBuilder clone() const { return *this; } @@ -1669,8 +1697,8 @@ public: } template - requires(std::is_base_of_v) - TypeToValue createUndef(T resultType) { + requires(std::is_base_of_v) + TypeToValue createUndef(T resultType) { return cast>(createUndef(resultType)); } @@ -1956,8 +1984,8 @@ public: } template - requires(std::is_base_of_v) PointerToType createTypePointer( - spv::StorageClass storageClass, T type) { + requires(std::is_base_of_v) + PointerToType createTypePointer(spv::StorageClass storageClass, T type) { return cast>( createTypePointer(storageClass, static_cast(type))); } @@ -1995,9 +2023,9 @@ public: } template - requires(std::is_base_of_v) - ConstantValue> createConstant( - T type, std::span values) { + requires(std::is_base_of_v) + ConstantValue> + createConstant(T type, std::span values) { auto region = globalRegion.pushOp(spv::Op::OpConstant, 3 + values.size()); auto id = newId>>(); region.pushIdUse(type); @@ -2009,16 +2037,14 @@ public: } template - requires(std::is_base_of_v) - ConstantValue> createConstant32(T type, - std::uint32_t value) { + requires(std::is_base_of_v) + ConstantValue> createConstant32(T type, std::uint32_t value) { return createConstant(type, std::array{value}); } template - requires(std::is_base_of_v) - ConstantValue> createConstant64(T type, - std::uint64_t value) { + requires(std::is_base_of_v) + ConstantValue> createConstant64(T type, std::uint64_t value) { return createConstant(type, std::array{static_cast(value), static_cast(value >> 32)}); diff --git a/hw/amdgpu/shader/include/amdgpu/shader/scf.hpp b/hw/amdgpu/shader/include/amdgpu/shader/scf.hpp index 9ad804115..c9755bc3b 100644 --- a/hw/amdgpu/shader/include/amdgpu/shader/scf.hpp +++ b/hw/amdgpu/shader/include/amdgpu/shader/scf.hpp @@ -40,8 +40,8 @@ public: Node *getParent() const { return mParent; } template - requires(std::is_base_of_v) auto getParent() const - -> decltype(dynCast(mParent)) { + requires(std::is_base_of_v) + auto getParent() const -> decltype(dynCast(mParent)) { return dynCast(mParent); } @@ -53,18 +53,18 @@ public: }; template -requires(std::is_base_of_v &&std::is_base_of_v) && - requires(ST *s) { - dynamic_cast(s); + requires(std::is_base_of_v && std::is_base_of_v) && + requires(ST *s) { dynamic_cast(s); } +T *dynCast(ST *s) { + return dynamic_cast(s); } -T *dynCast(ST *s) { return dynamic_cast(s); } template -requires(std::is_base_of_v &&std::is_base_of_v) && - requires(const ST *s) { - dynamic_cast(s); + requires(std::is_base_of_v && std::is_base_of_v) && + requires(const ST *s) { dynamic_cast(s); } +const T *dynCast(const ST *s) { + return dynamic_cast(s); } -const T *dynCast(const ST *s) { return dynamic_cast(s); } inline bool isNodeEqual(const Node *lhs, const Node *rhs) { if (lhs == rhs) { @@ -331,7 +331,8 @@ class Context { public: template - requires(std::is_constructible_v) T *create(ArgsT &&...args) { + requires(std::is_constructible_v) + T *create(ArgsT &&...args) { auto result = new T(std::forward(args)...); mNodes.push_front(std::unique_ptr{result}); return result; diff --git a/orbis-kernel/include/orbis/KernelAllocator.hpp b/orbis-kernel/include/orbis/KernelAllocator.hpp index b82352637..edf2aa9af 100644 --- a/orbis-kernel/include/orbis/KernelAllocator.hpp +++ b/orbis-kernel/include/orbis/KernelAllocator.hpp @@ -15,7 +15,9 @@ void kfree(void *ptr, std::size_t size); template struct kallocator { using value_type = T; - template struct rebind { using other = kallocator; }; + template struct rebind { + using other = kallocator; + }; T *allocate(std::size_t n) { return static_cast(kalloc(sizeof(T) * n, alignof(T))); @@ -47,7 +49,7 @@ using kunmap = template T *knew(Args &&...args) { auto loc = static_cast(utils::kalloc(sizeof(T), alignof(T))); auto res = std::construct_at(loc, std::forward(args)...); - if constexpr (requires(T * t) { t->_total_size = sizeof(T); }) + if constexpr (requires(T *t) { t->_total_size = sizeof(T); }) res->_total_size = sizeof(T); return res; } diff --git a/orbis-kernel/include/orbis/utils/IdMap.hpp b/orbis-kernel/include/orbis/utils/IdMap.hpp index 10856e436..d4127d9de 100644 --- a/orbis-kernel/include/orbis/utils/IdMap.hpp +++ b/orbis-kernel/include/orbis/utils/IdMap.hpp @@ -13,7 +13,8 @@ namespace orbis { inline namespace utils { template -requires(MaxId > MinId) class RcIdMap { + requires(MaxId > MinId) +class RcIdMap { static constexpr auto ChunkSize = std::min(MaxId - MinId, 64); static constexpr auto ChunkCount = (MaxId - MinId + ChunkSize - 1) / ChunkSize; @@ -190,7 +191,8 @@ public: template -requires(MaxId > MinId) struct OwningIdMap { + requires(MaxId > MinId) +struct OwningIdMap { static constexpr auto ChunkSize = std::min(MaxId - MinId, 64); static constexpr auto ChunkCount = (MaxId - MinId + ChunkSize - 1) / ChunkSize; @@ -248,8 +250,8 @@ requires(MaxId > MinId) struct OwningIdMap { BitSet fullChunks; template - requires(std::is_constructible_v) std::pair emplace( - ArgsT &&...args) { + requires(std::is_constructible_v) + std::pair emplace(ArgsT &&...args) { auto page = fullChunks.countr_one(); if (page == ChunkCount) { diff --git a/orbis-kernel/include/orbis/utils/Rc.hpp b/orbis-kernel/include/orbis/utils/Rc.hpp index 271b2b503..0c1ff824e 100644 --- a/orbis-kernel/include/orbis/utils/Rc.hpp +++ b/orbis-kernel/include/orbis/utils/Rc.hpp @@ -50,23 +50,24 @@ public: Ref() = default; template - requires(std::is_base_of_v) Ref(OT *ref) : m_ref(ref) { + requires(std::is_base_of_v) + Ref(OT *ref) : m_ref(ref) { if (m_ref != nullptr) { ref->incRef(); } } template - requires(std::is_base_of_v) Ref(const Ref &other) - : m_ref(other.get()) { + requires(std::is_base_of_v) + Ref(const Ref &other) : m_ref(other.get()) { if (m_ref != nullptr) { m_ref->incRef(); } } template - requires(std::is_base_of_v) Ref(Ref &&other) - : m_ref(other.release()) {} + requires(std::is_base_of_v) + Ref(Ref &&other) : m_ref(other.release()) {} Ref(const Ref &other) : m_ref(other.get()) { if (m_ref != nullptr) { @@ -76,19 +77,22 @@ public: Ref(Ref &&other) : m_ref(other.release()) {} template - requires(std::is_base_of_v) Ref &operator=(Ref &&other) { + requires(std::is_base_of_v) + Ref &operator=(Ref &&other) { other.swap(*this); return *this; } template - requires(std::is_base_of_v) Ref &operator=(OT *other) { + requires(std::is_base_of_v) + Ref &operator=(OT *other) { *this = Ref(other); return *this; } template - requires(std::is_base_of_v) Ref &operator=(const Ref &other) { + requires(std::is_base_of_v) + Ref &operator=(const Ref &other) { *this = Ref(other); return *this; } diff --git a/orbis-kernel/src/sysvec.cpp b/orbis-kernel/src/sysvec.cpp index 7adf640a6..07536514e 100644 --- a/orbis-kernel/src/sysvec.cpp +++ b/orbis-kernel/src/sysvec.cpp @@ -82,7 +82,8 @@ namespace detail { template struct WrapImpl; template -requires(sizeof...(Args) < 8) struct WrapImpl { + requires(sizeof...(Args) < 8) +struct WrapImpl { constexpr sysent operator()() { sysent result; result.narg = sizeof...(Args);