Skip to content

Commit d5d2d12

Browse files
authored
chore: Fix clang-tidy warnings (#197)
Following #78, this PR addresses new warnings from clang-tidy. After this PR being merged, PR #95 will run clang-tidy tests per-commit to `main` branch to make sure it always passes.
1 parent 9574e9d commit d5d2d12

6 files changed

Lines changed: 11 additions & 6 deletions

File tree

include/tvm/ffi/base_details.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ TVM_FFI_INLINE uint64_t StableHashCombine(uint64_t key, const T& value) {
200200
* \return the hash value.
201201
*/
202202
TVM_FFI_INLINE uint64_t StableHashBytes(const void* data_ptr, size_t size) {
203+
// NOLINTBEGIN(clang-analyzer-security.ArrayBound)
203204
const char* data = reinterpret_cast<const char*>(data_ptr);
204205
const constexpr uint64_t kMultiplier = 1099511628211ULL;
205206
const constexpr uint64_t kMod = 2147483647ULL;
@@ -215,14 +216,12 @@ TVM_FFI_INLINE uint64_t StableHashBytes(const void* data_ptr, size_t size) {
215216
// if alignment requirement is met, directly use load
216217
if (reinterpret_cast<uintptr_t>(it) % 8 == 0) {
217218
for (; it + 8 <= end; it += 8) {
218-
// NOLINTNEXTLINE(clang-analyzer-security.ArrayBound)
219219
u.b = *reinterpret_cast<const uint64_t*>(it);
220220
result = (result * kMultiplier + u.b) % kMod;
221221
}
222222
} else {
223223
// unaligned version
224224
for (; it + 8 <= end; it += 8) {
225-
// NOLINTNEXTLINE(clang-analyzer-security.ArrayBound)
226225
u.a[0] = it[0];
227226
u.a[1] = it[1];
228227
u.a[2] = it[2];
@@ -277,6 +276,7 @@ TVM_FFI_INLINE uint64_t StableHashBytes(const void* data_ptr, size_t size) {
277276
}
278277
result = (result * kMultiplier + u.b) % kMod;
279278
}
279+
// NOLINTEND(clang-analyzer-security.ArrayBound)
280280
return result;
281281
}
282282

include/tvm/ffi/c_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@
5656
#define TVM_FFI_DLL_EXPORT __attribute__((visibility("default")))
5757
#endif
5858

59+
// NOLINTBEGIN(modernize-macro-to-enum)
5960
/*! \brief TVM FFI major version. */
6061
#define TVM_FFI_VERSION_MAJOR 0
6162
/*! \brief TVM FFI minor version. */
6263
#define TVM_FFI_VERSION_MINOR 1
6364
/*! \brief TVM FFI patch version. */
6465
#define TVM_FFI_VERSION_PATCH 1
66+
// NOLINTEND(modernize-macro-to-enum)
6567

6668
#ifdef __cplusplus
6769
extern "C" {

include/tvm/ffi/container/array.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ class Array : public ObjectRef {
447447
* \tparam IterType The type of iterator
448448
*/
449449
template <typename IterType>
450-
Array(IterType first, IterType last) {
450+
Array(IterType first, IterType last) { // NOLINT(performance-unnecessary-value-param)
451451
static_assert(is_valid_iterator_v<T, IterType>,
452452
"IterType cannot be inserted into a tvm::Array<T>");
453453
Assign(first, last);
@@ -817,7 +817,7 @@ class Array : public ObjectRef {
817817
* \tparam IterType The type of iterator
818818
*/
819819
template <typename IterType>
820-
void Assign(IterType first, IterType last) {
820+
void Assign(IterType first, IterType last) { // NOLINT(performance-unnecessary-value-param)
821821
int64_t cap = std::distance(first, last);
822822
if (cap < 0) {
823823
TVM_FFI_THROW(ValueError) << "cannot construct an Array of negative size";

include/tvm/ffi/reflection/access_path.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ class AccessPath : public ObjectRef {
329329
* \param end The end of the iterator range.
330330
* \return The access path.
331331
*/
332-
template <typename Iter>
332+
template <typename Iter> // NOLINTNEXTLINE(performance-unnecessary-value-param)
333333
static AccessPath FromSteps(Iter begin, Iter end) {
334334
AccessPath path = AccessPath::Root();
335335
for (Iter it = begin; it != end; ++it) {

include/tvm/ffi/reflection/registry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ class ReflectionDefBase {
296296
static_assert(std::is_base_of_v<ObjectRef, Class> || std::is_base_of_v<Object, Class>,
297297
"Class must be derived from ObjectRef or Object");
298298
if constexpr (std::is_base_of_v<ObjectRef, Class>) {
299-
auto fwrap = [func](const Class target, Args... params) -> R {
299+
auto fwrap = [func](const Class& target, Args... params) -> R {
300300
// call method pointer
301301
return (target.*func)(std::forward<Args>(params)...);
302302
};

src/ffi/testing/testing.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ TVM_FFI_NO_INLINE void TestApply(PackedArgs args, Any* ret) {
176176
f.CallPacked(args.Slice(1), ret);
177177
}
178178

179+
// NOLINTNEXTLINE(bugprone-reserved-identifier)
179180
int __add_one_c_symbol(void*, const TVMFFIAny* args, int32_t num_args, TVMFFIAny* ret) {
180181
TVM_FFI_SAFE_CALL_BEGIN();
181182
int x = reinterpret_cast<const AnyView*>(args)[0].cast<int>();
@@ -261,10 +262,12 @@ TVM_FFI_STATIC_INIT_BLOCK() {
261262
.def("testing.get_add_one_c_symbol",
262263
[]() {
263264
TVMFFISafeCallType symbol = __add_one_c_symbol;
265+
// NOLINTNEXTLINE(bugprone-casting-through-void)
264266
return reinterpret_cast<int64_t>(reinterpret_cast<void*>(symbol));
265267
})
266268
.def("testing.get_mlir_add_one_c_symbol",
267269
[]() {
270+
// NOLINTNEXTLINE(bugprone-casting-through-void)
268271
return reinterpret_cast<int64_t>(reinterpret_cast<void*>(_mlir_add_one_c_symbol));
269272
})
270273
.def_method("testing.TestIntPairSum", &TestIntPair::Sum, "Get sum of the pair");

0 commit comments

Comments
 (0)