diff --git a/.clang-tidy b/.clang-tidy index 6371a8a89..37f90618f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -10,28 +10,34 @@ cppcoreguidelines-*,\ -cppcoreguidelines-avoid-c-arrays,\ -cppcoreguidelines-avoid-non-const-global-variables,\ -cppcoreguidelines-macro-usage,\ +-cppcoreguidelines-missing-std-forward,\ -cppcoreguidelines-owning-memory,\ -cppcoreguidelines-pro-bounds-pointer-arithmetic,\ -cppcoreguidelines-pro-type-const-cast,\ -cppcoreguidelines-pro-type-vararg,\ +-cppcoreguidelines-rvalue-reference-param-not-moved,\ hicpp-*,\ -hicpp-avoid-c-arrays,\ -hicpp-vararg,\ -hicpp-use-auto,\ misc-*,\ -misc-const-correctness,\ +-misc-include-cleaner,\ modernize-*,\ -modernize-avoid-c-arrays,\ -modernize-use-auto,\ -modernize-use-nodiscard,\ -modernize-use-trailing-return-type,\ performance-*,\ +-performance-avoid-endl,\ portability-*,\ readability-*,\ -readability-avoid-const-params-in-decls,\ -readability-const-return-type,\ -readability-function-cognitive-complexity,\ -readability-identifier-length,\ +-readability-redundant-casting,\ +-readability-redundant-member-init,\ " HeaderFilterRegex: 'src|benchmark/stdgpu|test/stdgpu' ... diff --git a/src/stdgpu/atomic.cuh b/src/stdgpu/atomic.cuh index 76b00d5fa..b1bd86fa9 100644 --- a/src/stdgpu/atomic.cuh +++ b/src/stdgpu/atomic.cuh @@ -28,6 +28,7 @@ */ #include +#include #include #include @@ -42,16 +43,52 @@ namespace stdgpu * \ingroup atomic * \brief The memory order types for atomic operations */ -enum memory_order +enum class memory_order : std::int8_t { - memory_order_relaxed, /**< memory_order_relaxed */ - memory_order_consume, /**< memory_order_consume */ - memory_order_acquire, /**< memory_order_acquire */ - memory_order_release, /**< memory_order_release */ - memory_order_acq_rel, /**< memory_order_acq_rel */ - memory_order_seq_cst /**< memory_order_seq_cst */ + relaxed, /**< relaxed */ + consume, /**< consume */ + acquire, /**< acquire */ + release, /**< release */ + acq_rel, /**< acq_rel */ + seq_cst /**< seq_cst */ }; +/** + * \ingroup atomic + * \brief memory_order_relaxed + */ +inline constexpr memory_order memory_order_relaxed = memory_order::relaxed; + +/** + * \ingroup atomic + * \brief memory_order_consume + */ +inline constexpr memory_order memory_order_consume = memory_order::consume; + +/** + * \ingroup atomic + * \brief memory_order_acquire + */ +inline constexpr memory_order memory_order_acquire = memory_order::acquire; + +/** + * \ingroup atomic + * \brief memory_order_release + */ +inline constexpr memory_order memory_order_release = memory_order::release; + +/** + * \ingroup atomic + * \brief memory_order_acq_rel + */ +inline constexpr memory_order memory_order_acq_rel = memory_order::acq_rel; + +/** + * \ingroup atomic + * \brief memory_order_seq_cst + */ +inline constexpr memory_order memory_order_seq_cst = memory_order::seq_cst; + /** * \ingroup atomic * \brief A synchronization fence enforcing the given memory order diff --git a/src/stdgpu/impl/algorithm_detail.h b/src/stdgpu/impl/algorithm_detail.h index fd816d328..9f275fd81 100644 --- a/src/stdgpu/impl/algorithm_detail.h +++ b/src/stdgpu/impl/algorithm_detail.h @@ -45,7 +45,7 @@ clamp(const T& v, const T& lower, const T& upper) { STDGPU_EXPECTS(!(upper < lower)); - return v < lower ? lower : upper < v ? upper : v; + return v < lower ? lower : upper < v ? upper : v; // NOLINT(readability-avoid-nested-conditional-operator) } template class count_block_bits { public: - inline count_block_bits(Block* bit_blocks, const index_t size) + count_block_bits(Block* bit_blocks, const index_t size) : _bit_blocks(bit_blocks) , _size(size) { } - inline STDGPU_HOST_DEVICE index_t + STDGPU_HOST_DEVICE index_t operator()(const index_t i) const { return static_cast(popcount(block_mask(i) & _bit_blocks[i])); } private: - inline STDGPU_HOST_DEVICE Block + STDGPU_HOST_DEVICE Block block_mask(const index_t i) const { index_t remaining_bits = _size - i * _bits_per_block; @@ -162,12 +162,12 @@ template class flip_bits { public: - inline explicit flip_bits(Block* bit_blocks) + explicit flip_bits(Block* bit_blocks) : _bit_blocks(bit_blocks) { } - inline STDGPU_HOST_DEVICE void + STDGPU_HOST_DEVICE void operator()(const index_t i) { _bit_blocks[i] = ~_bit_blocks[i]; diff --git a/src/stdgpu/impl/functional_detail.h b/src/stdgpu/impl/functional_detail.h index 27b4a9aee..fcb733a2c 100644 --- a/src/stdgpu/impl/functional_detail.h +++ b/src/stdgpu/impl/functional_detail.h @@ -48,7 +48,7 @@ struct hash_base template struct hash_base { - inline STDGPU_HOST_DEVICE std::size_t + STDGPU_HOST_DEVICE std::size_t operator()(const T& key) const { return hash>()(static_cast>(key)); diff --git a/src/stdgpu/impl/iterator_detail.h b/src/stdgpu/impl/iterator_detail.h index ba3442f4d..513d2e5fd 100644 --- a/src/stdgpu/impl/iterator_detail.h +++ b/src/stdgpu/impl/iterator_detail.h @@ -42,6 +42,7 @@ template index64_t size(T* array) { + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) index64_t array_size_bytes = size(static_cast(const_cast*>(array))); if (array_size_bytes % static_cast(sizeof(T)) != 0) // NOLINT(bugprone-sizeof-expression) diff --git a/src/stdgpu/impl/memory.cpp b/src/stdgpu/impl/memory.cpp index 68b1b9596..dd027d3f6 100644 --- a/src/stdgpu/impl/memory.cpp +++ b/src/stdgpu/impl/memory.cpp @@ -15,6 +15,7 @@ #include +#include #include #include #include diff --git a/src/stdgpu/impl/memory_detail.h b/src/stdgpu/impl/memory_detail.h index e2cc86911..8b54bf1bb 100644 --- a/src/stdgpu/impl/memory_detail.h +++ b/src/stdgpu/impl/memory_detail.h @@ -377,12 +377,15 @@ copyDevice2HostArray(const T* source_device_array, T* destination_host_array, const MemoryCopy check_safety) { - stdgpu::detail::memcpy(destination_host_array, - source_device_array, - count * static_cast(sizeof(T)), // NOLINT(bugprone-sizeof-expression) - stdgpu::dynamic_memory_type::host, - stdgpu::dynamic_memory_type::device, - check_safety != MemoryCopy::RANGE_CHECK); + stdgpu::detail::memcpy( + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) + static_cast(const_cast*>(destination_host_array)), + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) + static_cast(const_cast*>(source_device_array)), + count * static_cast(sizeof(T)), // NOLINT(bugprone-sizeof-expression) + stdgpu::dynamic_memory_type::host, + stdgpu::dynamic_memory_type::device, + check_safety != MemoryCopy::RANGE_CHECK); } template @@ -392,12 +395,15 @@ copyHost2DeviceArray(const T* source_host_array, T* destination_device_array, const MemoryCopy check_safety) { - stdgpu::detail::memcpy(destination_device_array, - source_host_array, - count * static_cast(sizeof(T)), // NOLINT(bugprone-sizeof-expression) - stdgpu::dynamic_memory_type::device, - stdgpu::dynamic_memory_type::host, - check_safety != MemoryCopy::RANGE_CHECK); + stdgpu::detail::memcpy( + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) + static_cast(const_cast*>(destination_device_array)), + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) + static_cast(const_cast*>(source_host_array)), + count * static_cast(sizeof(T)), // NOLINT(bugprone-sizeof-expression) + stdgpu::dynamic_memory_type::device, + stdgpu::dynamic_memory_type::host, + check_safety != MemoryCopy::RANGE_CHECK); } template @@ -407,12 +413,15 @@ copyHost2HostArray(const T* source_host_array, T* destination_host_array, const MemoryCopy check_safety) { - stdgpu::detail::memcpy(destination_host_array, - source_host_array, - count * static_cast(sizeof(T)), // NOLINT(bugprone-sizeof-expression) - stdgpu::dynamic_memory_type::host, - stdgpu::dynamic_memory_type::host, - check_safety != MemoryCopy::RANGE_CHECK); + stdgpu::detail::memcpy( + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) + static_cast(const_cast*>(destination_host_array)), + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) + static_cast(const_cast*>(source_host_array)), + count * static_cast(sizeof(T)), // NOLINT(bugprone-sizeof-expression) + stdgpu::dynamic_memory_type::host, + stdgpu::dynamic_memory_type::host, + check_safety != MemoryCopy::RANGE_CHECK); } template @@ -422,12 +431,15 @@ copyDevice2DeviceArray(const T* source_device_array, T* destination_device_array, const MemoryCopy check_safety) { - stdgpu::detail::memcpy(destination_device_array, - source_device_array, - count * static_cast(sizeof(T)), // NOLINT(bugprone-sizeof-expression) - stdgpu::dynamic_memory_type::device, - stdgpu::dynamic_memory_type::device, - check_safety != MemoryCopy::RANGE_CHECK); + stdgpu::detail::memcpy( + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) + static_cast(const_cast*>(destination_device_array)), + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) + static_cast(const_cast*>(source_device_array)), + count * static_cast(sizeof(T)), // NOLINT(bugprone-sizeof-expression) + stdgpu::dynamic_memory_type::device, + stdgpu::dynamic_memory_type::device, + check_safety != MemoryCopy::RANGE_CHECK); } namespace stdgpu @@ -517,7 +529,8 @@ void safe_device_allocator::deallocate(T* p, index64_t n) { deregister_memory(p, n, memory_type); - detail::deallocate(static_cast(p), + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) + detail::deallocate(static_cast(const_cast*>(p)), n * static_cast(sizeof(T)), // NOLINT(bugprone-sizeof-expression) memory_type); } @@ -543,7 +556,8 @@ void safe_host_allocator::deallocate(T* p, index64_t n) { deregister_memory(p, n, memory_type); - detail::deallocate(static_cast(p), + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) + detail::deallocate(static_cast(const_cast*>(p)), n * static_cast(sizeof(T)), // NOLINT(bugprone-sizeof-expression) memory_type); } @@ -569,7 +583,8 @@ void safe_managed_allocator::deallocate(T* p, index64_t n) { deregister_memory(p, n, memory_type); - detail::deallocate(static_cast(p), + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) + detail::deallocate(static_cast(const_cast*>(p)), n * static_cast(sizeof(T)), // NOLINT(bugprone-sizeof-expression) memory_type); } @@ -695,7 +710,8 @@ template STDGPU_HOST_DEVICE T* construct_at(T* p, Args&&... args) { - return ::new (static_cast(p)) T(forward(args)...); + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) + return ::new (static_cast(const_cast*>(p))) T(forward(args)...); } template @@ -793,6 +809,7 @@ template dynamic_memory_type get_dynamic_memory_type(T* array) { + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) return get_dynamic_memory_type(static_cast(const_cast*>(array))); } @@ -804,6 +821,7 @@ template void register_memory(T* p, index64_t n, dynamic_memory_type memory_type) { + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) register_memory(static_cast(const_cast*>(p)), n * static_cast(sizeof(T)), // NOLINT(bugprone-sizeof-expression) memory_type); @@ -817,6 +835,7 @@ template void deregister_memory(T* p, index64_t n, dynamic_memory_type memory_type) { + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) deregister_memory(static_cast(const_cast*>(p)), n * static_cast(sizeof(T)), // NOLINT(bugprone-sizeof-expression) memory_type); @@ -830,6 +849,7 @@ template index64_t size_bytes(T* array) { + // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) return size_bytes(static_cast(const_cast*>(array))); } diff --git a/src/stdgpu/impl/unordered_base.cuh b/src/stdgpu/impl/unordered_base.cuh index f9605a315..ca6b538e4 100644 --- a/src/stdgpu/impl/unordered_base.cuh +++ b/src/stdgpu/impl/unordered_base.cuh @@ -16,6 +16,8 @@ #ifndef STDGPU_UNORDERED_BASE_H #define STDGPU_UNORDERED_BASE_H +#include + #include #include #include @@ -35,7 +37,7 @@ namespace stdgpu::detail /** * \brief Status flags for try_insert and try_erase */ -enum class operation_status +enum class operation_status : std::int8_t { success, /**< Operation succeeded */ failed_no_action_required, /**< Operation failed because no action is required */ diff --git a/src/stdgpu/memory.h b/src/stdgpu/memory.h index 7a5f0d81b..489cc6542 100644 --- a/src/stdgpu/memory.h +++ b/src/stdgpu/memory.h @@ -25,6 +25,7 @@ * \file stdgpu/memory.h */ +#include #include #include #include @@ -39,7 +40,7 @@ * \ingroup memory * \brief The place to initialize the created array */ -enum class Initialization +enum class Initialization : std::int8_t { HOST, /**< The array is initialized on the host (CPU) */ DEVICE /**< The array is initialized on the device (GPU) */ @@ -121,7 +122,7 @@ destroyManagedArray(T*& managed_array); * \ingroup memory * \brief The copy check states */ -enum class MemoryCopy +enum class MemoryCopy : std::int8_t { NO_CHECK, /**< No checks should be performed. This is useful when copying from/to arrays not created by our API, e.g. created by 3rd party libraries or pointers to local variables. */ @@ -356,7 +357,7 @@ class device_unique_object * \ingroup memory * \brief The types of a dynamically allocated array */ -enum class dynamic_memory_type +enum class dynamic_memory_type : std::int8_t { host, /**< The array is allocated on the host (CPU) */ device, /**< The array is allocated on the device (GPU) */ diff --git a/src/stdgpu/utility.h b/src/stdgpu/utility.h index 04c2afae5..a81f59cf4 100644 --- a/src/stdgpu/utility.h +++ b/src/stdgpu/utility.h @@ -182,9 +182,9 @@ struct pair constexpr STDGPU_HOST_DEVICE pair& operator=(pair&& p); - // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members,misc-non-private-member-variables-in-classes) first_type first; /**< First element of pair */ - // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members,misc-non-private-member-variables-in-classes) second_type second; /**< Second element of pair */ }; diff --git a/tests/stdgpu/functional.cpp b/tests/stdgpu/functional.cpp index 4860ed928..2a675fb7d 100644 --- a/tests/stdgpu/functional.cpp +++ b/tests/stdgpu/functional.cpp @@ -15,6 +15,7 @@ #include +#include #include #include #include @@ -247,7 +248,7 @@ TEST_F(stdgpu_functional, hash_long_double) hash_check_floating_point_random(); } -enum old_enum +enum old_enum : std::int8_t { zero = 0, one = 1, @@ -270,7 +271,7 @@ TEST_F(stdgpu_functional, hash_enum) EXPECT_GT(static_cast(hashes.size()), 4 * 90 / 100); } -enum class scoped_enum +enum class scoped_enum : std::int8_t { zero = 0, one = 1, diff --git a/tests/stdgpu/iterator.cpp b/tests/stdgpu/iterator.cpp index a4c8e3d23..05a07daed 100644 --- a/tests/stdgpu/iterator.cpp +++ b/tests/stdgpu/iterator.cpp @@ -347,7 +347,7 @@ class back_insert_interface } private: - std::vector& _vector; + std::vector& _vector; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) }; class front_insert_interface @@ -367,7 +367,7 @@ class front_insert_interface } private: - std::vector& _vector; + std::vector& _vector; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) }; class insert_interface @@ -387,7 +387,7 @@ class insert_interface } private: - std::vector& _vector; + std::vector& _vector; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) }; TEST_F(stdgpu_iterator, back_inserter) diff --git a/tests/stdgpu/limits.cpp b/tests/stdgpu/limits.cpp index 1bdaaed8c..1e9d9e1f5 100644 --- a/tests/stdgpu/limits.cpp +++ b/tests/stdgpu/limits.cpp @@ -210,7 +210,7 @@ TEST_F(stdgpu_limits, long_double) class NonArithmeticType { public: - inline STDGPU_HOST_DEVICE bool + STDGPU_HOST_DEVICE bool operator==(const NonArithmeticType& other) const { return x == other.x;