Skip to content

Commit bc5b06c

Browse files
committed
Extend CPPCHECK scope to aten kernels
Remove kernels/aten from the CPPCHECK exclude list after fixing its only diagnostic. The _empty_dim_order validation kept the fallback dim_order vector in the outer function scope so that an ArrayRef could be assigned after the optional branch. Move the shared validation into a local helper and create the fallback vector only on the no-dim_order path, which satisfies cppcheck without changing the validation behavior. Signed-off-by: Per Held <per.held@arm.com> Change-Id: Ic7f4d859d7d0aa531ebe51e3c5ea73f46bb28ef4
1 parent 0b13b6a commit bc5b06c

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

.lintrunner.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ exclude_patterns = [
193193
'extension/wasm/**',
194194

195195
# Kernel areas to onboard separately.
196-
'kernels/aten/**',
197196
'kernels/optimized/**',
198197
'kernels/portable/**',
199198
'kernels/prim_ops/**',

kernels/aten/cpu/op__empty_dim_order.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* Copyright 2026 Arm Limited and/or its affiliates.
34
* All rights reserved.
45
*
56
* This source code is licensed under the BSD-style license found in the
@@ -26,23 +27,9 @@ const size_t kMaxNumOfDimensions = 16;
2627

2728
namespace {
2829

29-
inline bool _check__empty_out_dim_order(
30-
OptionalIntArrayRef dim_order,
30+
inline bool check_empty_out_dim_order_ref(
31+
executorch::aten::ArrayRef<int64_t> dim_order_ref,
3132
Tensor& out) {
32-
executorch::aten::ArrayRef<int64_t> dim_order_ref;
33-
std::vector<int64_t> dim_order_vec;
34-
35-
if (dim_order.has_value()) {
36-
// out tensor's dim order shall equal to input dim order
37-
dim_order_ref = executorch::aten::ArrayRef<int64_t>(
38-
dim_order.value().data(), dim_order.value().size());
39-
} else { // dim_order is not set, out tensor should be contiguous dim order
40-
for (int i = 0; i < out.dim(); i++) {
41-
dim_order_vec.push_back(i);
42-
}
43-
dim_order_ref = executorch::aten::ArrayRef<int64_t>(dim_order_vec);
44-
}
45-
4633
// dim order size shall equal to input dim
4734
ET_LOG_AND_RETURN_IF_FALSE(dim_order_ref.size() == out.dim());
4835

@@ -65,6 +52,24 @@ inline bool _check__empty_out_dim_order(
6552
return true;
6653
}
6754

55+
inline bool _check__empty_out_dim_order(
56+
OptionalIntArrayRef dim_order,
57+
Tensor& out) {
58+
if (dim_order.has_value()) {
59+
// out tensor's dim order shall equal to input dim order
60+
return check_empty_out_dim_order_ref(executorch::aten::ArrayRef<int64_t>(
61+
dim_order.value().data(), dim_order.value().size()));
62+
} else { // dim_order is not set, out tensor should be contiguous dim order
63+
std::vector<int64_t> dim_order_vec;
64+
dim_order_vec.reserve(out.dim());
65+
for (int i = 0; i < out.dim(); i++) {
66+
dim_order_vec.push_back(i);
67+
}
68+
return check_empty_out_dim_order_ref(
69+
executorch::aten::ArrayRef<int64_t>(dim_order_vec));
70+
}
71+
}
72+
6873
} // namespace
6974

7075
/*

0 commit comments

Comments
 (0)