Skip to content

Commit e93a285

Browse files
committed
Extend CPPCHECK scope to portable kernels
Remove the broad kernels/portable CPPCHECK exclusion and keep the remaining suppressions scoped to the portable tree. Portable kernel entry points are referenced through generated registration tables, which cppcheck CTU does not see as direct C++ calls. Suppress the resulting unusedFunction reports for this tree. Cppcheck also does not parse several ExecuTorch macro idioms used heavily in portable kernels, including empty macro arguments and printf-style macros concatenated into string literals. Keep those parser suppressions scoped to portable kernels instead of adding inline suppressions throughout the tree. Fix small real findings by removing an impossible unsigned comparison and cleaning up unused test setup plus a stray comma expression. Signed-off-by: Per Held <per.held@arm.com> Change-Id: I6279a123b487d32b5811fdbe46ae4f2e82dcabd5
1 parent fba18e2 commit e93a285

3 files changed

Lines changed: 21 additions & 9 deletions

File tree

.lintrunner.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ exclude_patterns = [
194194

195195
# Kernel areas to onboard separately.
196196
'kernels/optimized/**',
197-
'kernels/portable/**',
198197

199198
# Runtime areas to onboard incrementally.
200199
'runtime/backend/**',
@@ -243,6 +242,23 @@ command = [
243242
'--extra-arg=--suppress=duplicateBranch:*kernels/test/*',
244243
'--extra-arg=--suppress=useStlAlgorithm:*kernels/test/*',
245244
'--extra-arg=--suppress=functionStatic:*kernels/test/*',
245+
# Portable kernels are referenced through generated registration tables,
246+
# which cppcheck CTU does not see as direct C++ calls.
247+
'--extra-arg=--suppress=unusedFunction:*kernels/portable/*',
248+
# Cppcheck does not parse several ExecuTorch macro idioms used heavily in
249+
# portable kernels, including empty macro arguments and printf-style macros
250+
# concatenated into string literals.
251+
'--extra-arg=--suppress=unknownMacro:*kernels/portable/*',
252+
'--extra-arg=--suppress=syntaxError:*kernels/portable/*',
253+
# Keep style-only portable-kernel findings scoped to this tree rather than
254+
# rewriting broad helper code for lint-only advice.
255+
'--extra-arg=--suppress=useStlAlgorithm:*kernels/portable/*',
256+
'--extra-arg=--suppress=variableScope:*kernels/portable/*',
257+
'--extra-arg=--suppress=constParameterReference:*kernels/portable/*',
258+
'--extra-arg=--suppress=constParameterPointer:*kernels/portable/*',
259+
'--extra-arg=--suppress=functionStatic:*kernels/portable/*',
260+
'--extra-arg=--suppress=knownConditionTrueFalse:*kernels/portable/*',
261+
'--extra-arg=--suppress=invalidFunctionArg:*kernels/portable/*',
246262
'--',
247263
'@{{PATHSFILE}}'
248264
]

kernels/portable/cpu/util/copy_ops_util.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Copyright (c) Meta Platforms, Inc. and affiliates.
33
* All rights reserved.
4+
* Copyright 2026 Arm Limited and/or its affiliates.
45
*
56
* This source code is licensed under the BSD-style license found in the
67
* LICENSE file in the root directory of this source tree.
@@ -241,7 +242,7 @@ bool check_permute_copy_args(const Tensor& in, IntArrayRef dims, Tensor& out) {
241242
size_t dim = dims[i] >= 0 ? dims[i] : in.dim() + dims[i];
242243

243244
// Internal check, since we have already validated this
244-
ET_LOG_AND_RETURN_IF_FALSE(dim < kTensorDimensionLimit && dim >= 0);
245+
ET_LOG_AND_RETURN_IF_FALSE(dim < kTensorDimensionLimit);
245246

246247
// Check that the dimension hasn't been seen previously.
247248
ET_CHECK_OR_RETURN_FALSE(

kernels/portable/cpu/util/test/reduce_test.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Copyright (c) Meta Platforms, Inc. and affiliates.
33
* All rights reserved.
4+
* Copyright 2026 Arm Limited and/or its affiliates.
45
*
56
* This source code is licensed under the BSD-style license found in the
67
* LICENSE file in the root directory of this source tree.
@@ -50,8 +51,6 @@ void _apply_over_dim_list(
5051

5152
TEST(ReduceUtilTest, ApplyOverDim) {
5253
TensorFactory<ScalarType::Long> tf;
53-
optional<ArrayRef<int64_t>> dim_list;
54-
5554
Tensor in = tf.zeros({2, 4, 5, 3});
5655
_apply_over_dim(in, 0);
5756
// clang-format off
@@ -85,8 +84,6 @@ TEST(ReduceUtilTest, ApplyOverDim) {
8584
// clang-format on
8685

8786
in = tf.zeros({2, 4, 5, 3});
88-
int64_t dim_array_2[1] = {2};
89-
dim_list = optional<ArrayRef<int64_t>>(ArrayRef<int64_t>{dim_array_2, 1});
9087
_apply_over_dim(in, 2);
9188
// clang-format off
9289
EXPECT_TENSOR_EQ(in, tf.make({2, 4, 5, 3}, {
@@ -103,8 +100,6 @@ TEST(ReduceUtilTest, ApplyOverDim) {
103100
// clang-format on
104101

105102
in = tf.zeros({2, 4, 5, 3});
106-
int64_t dim_array_3[1] = {3};
107-
dim_list = optional<ArrayRef<int64_t>>(ArrayRef<int64_t>{dim_array_3, 1});
108103
_apply_over_dim(in, 3);
109104
// clang-format off
110105
EXPECT_TENSOR_EQ(in, tf.make({2, 4, 5, 3}, {
@@ -470,7 +465,7 @@ TEST(ReduceUtilTest, ApplyOnZeroDimTensorOverDimListNonEmpty) {
470465
optional<ArrayRef<int64_t>>(ArrayRef<int64_t>{dim_array_0, 1});
471466

472467
Tensor in = tf.ones({});
473-
_apply_over_dim_list(in, dim_list), "";
468+
_apply_over_dim_list(in, dim_list);
474469
EXPECT_TENSOR_EQ(in, tf.make({}, {0}));
475470
}
476471

0 commit comments

Comments
 (0)