This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-ffi.git
The following commit(s) were added to refs/heads/main by this push:
new 262ca30 chore(lint): Fix clang-tidy warnings (#340)
262ca30 is described below
commit 262ca30aad858d818b919d5e670e80b7a57b89e4
Author: Junru Shao <[email protected]>
AuthorDate: Fri Dec 12 11:22:40 2025 -0800
chore(lint): Fix clang-tidy warnings (#340)
---
include/tvm/ffi/container/tensor.h | 4 ++--
src/ffi/tensor.cc | 5 +++--
tests/cpp/test_tensor.cc | 8 ++++++--
3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/include/tvm/ffi/container/tensor.h
b/include/tvm/ffi/container/tensor.h
index 6d7e637..857bd6b 100644
--- a/include/tvm/ffi/container/tensor.h
+++ b/include/tvm/ffi/container/tensor.h
@@ -189,7 +189,7 @@ class TensorObjFromNDAlloc : public TensorObj {
template <typename... ExtraArgs>
TensorObjFromNDAlloc(TNDAlloc alloc, ffi::ShapeView shape, DLDataType dtype,
DLDevice device,
ExtraArgs&&... extra_args)
- : alloc_(alloc) {
+ : alloc_(std::move(alloc)) {
this->device = device;
this->ndim = static_cast<int>(shape.size());
this->dtype = dtype;
@@ -205,7 +205,7 @@ class TensorObjFromNDAlloc : public TensorObj {
template <typename... ExtraArgs>
TensorObjFromNDAlloc(TNDAlloc alloc, const DLTensor& prototype,
ExtraArgs&&... extra_args)
- : alloc_(alloc) {
+ : alloc_(std::move(alloc)) {
*static_cast<DLTensor*>(this) = prototype;
this->shape = reinterpret_cast<int64_t*>(reinterpret_cast<char*>(this) +
sizeof(Self));
this->strides = this->shape + prototype.ndim;
diff --git a/src/ffi/tensor.cc b/src/ffi/tensor.cc
index 2033690..0a1563e 100644
--- a/src/ffi/tensor.cc
+++ b/src/ffi/tensor.cc
@@ -56,7 +56,8 @@ int TVMFFITensorCreateUnsafeView(TVMFFIObjectHandle source,
const DLTensor* prot
class ViewNDAlloc {
public:
- ViewNDAlloc(tvm::ffi::ObjectPtr<tvm::ffi::TensorObj> tensor) :
tensor_(tensor) {}
+ explicit ViewNDAlloc(tvm::ffi::ObjectPtr<tvm::ffi::TensorObj> tensor)
+ : tensor_(std::move(tensor)) {}
void AllocData(DLTensor* tensor, void* data_ptr) { tensor->data =
data_ptr; }
void FreeData(DLTensor* tensor) {}
@@ -65,7 +66,7 @@ int TVMFFITensorCreateUnsafeView(TVMFFIObjectHandle source,
const DLTensor* prot
};
void* source_data_ptr = prototype->data;
- size_t num_extra_i64_at_tail = prototype->ndim * 2;
+ size_t num_extra_i64_at_tail = static_cast<size_t>(prototype->ndim) * 2;
ViewNDAlloc alloc(source_tensor);
tvm::ffi::Tensor ret_tensor(
tvm::ffi::make_inplace_array_object<tvm::ffi::details::TensorObjFromNDAlloc<ViewNDAlloc>,
diff --git a/tests/cpp/test_tensor.cc b/tests/cpp/test_tensor.cc
index ac3dbdb..b5c82bc 100644
--- a/tests/cpp/test_tensor.cc
+++ b/tests/cpp/test_tensor.cc
@@ -213,7 +213,9 @@ TEST(Tensor, TensorViewAsStrided) {
// Fill with sequential values: [0, 1, 2, 3, 4, 5]
float* data = reinterpret_cast<float*>(tensor.data_ptr());
- for (int64_t i = 0; i < tensor.numel(); ++i) {
+ size_t element_capacity = GetDataSize(tensor) / sizeof(float);
+ ASSERT_EQ(element_capacity, static_cast<size_t>(tensor.numel()));
+ for (size_t i = 0; i < element_capacity; ++i) {
data[i] = static_cast<float>(i);
}
@@ -292,7 +294,9 @@ TEST(Tensor, AsStrided) {
// Fill with sequential values: [0, 1, 2, 3, 4, 5]
float* data = reinterpret_cast<float*>(tensor.data_ptr());
- for (int64_t i = 0; i < tensor.numel(); ++i) {
+ size_t element_capacity = GetDataSize(tensor) / sizeof(float);
+ ASSERT_EQ(element_capacity, static_cast<size_t>(tensor.numel()));
+ for (size_t i = 0; i < element_capacity; ++i) {
data[i] = static_cast<float>(i);
}