Skip to content

Commit cbcdfc1

Browse files
authored
Arm backend: Make banned functions list more suitable (pytorch#22080)
* Amend list to be more suitable for the backend * Expand linting to backends/arm Change-Id: I3d69a71bafa0eba0e724a1ff016d9159f382f8b1 cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani Signed-off-by: Tom Allsop <tom.allsop@arm.com>
1 parent 845e28d commit cbcdfc1

6 files changed

Lines changed: 39 additions & 72 deletions

File tree

‎.lintrunner.toml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,11 @@ is_formatter = true
744744
[[linter]]
745745
code = 'CPP_BANNED_FUNCTIONS'
746746
include_patterns = [
747+
'backends/arm/**/*.c',
748+
'backends/arm/**/*.cc',
749+
'backends/arm/**/*.cpp',
750+
'backends/arm/**/*.h',
751+
'backends/arm/**/*.hpp',
747752
'examples/arm/**/*.c',
748753
'examples/arm/**/*.cc',
749754
'examples/arm/**/*.cpp',

‎backends/arm/runtime/EthosUBackend_Cortex_A.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ Error invoke_linux_driver(
323323
}
324324
} // namespace
325325

326+
// Used by EthosUBackend.cpp through EthosUBackend_Internal.h.
327+
// cppcheck-suppress unusedFunction
326328
PlatformState* platform_init(
327329
ArrayRef<CompileSpec> specs,
328330
MemoryAllocator* allocator) {
@@ -335,10 +337,14 @@ PlatformState* platform_init(
335337
return state;
336338
}
337339

340+
// Used by EthosUBackend.cpp through EthosUBackend_Internal.h.
341+
// cppcheck-suppress unusedFunction
338342
void platform_destroy(PlatformState* state) {
339343
delete state;
340344
}
341345

346+
// Used by EthosUBackend.cpp through EthosUBackend_Internal.h.
347+
// cppcheck-suppress unusedFunction
342348
Error platform_execute(
343349
BackendExecutionContext& /*context*/,
344350
const ExecutionHandle* execution_handle,

‎backends/arm/runtime/VGFBackend.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,4 +1145,4 @@ VkResult vkml_allocate_basics(
11451145

11461146
} // namespace vgf
11471147
} // namespace backends
1148-
} // namespace executorch
1148+
} // namespace executorch

‎backends/arm/runtime/VGFNeuralStatistics.cpp‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ std::string serialize_vgf_neural_statistics_collection(
524524
return out.str();
525525
}
526526

527+
// Used by vgf_neural_statistics_test.cpp through VGFNeuralStatistics.h.
528+
// cppcheck-suppress unusedFunction
527529
std::string make_vgf_neural_statistics_unavailable_metadata(
528530
const std::string& reason) {
529531
VgfNeuralStatisticsCollection collection;
@@ -533,6 +535,8 @@ std::string make_vgf_neural_statistics_unavailable_metadata(
533535
return serialize_vgf_neural_statistics_collection(collection);
534536
}
535537

538+
// Used by VGFSetup.cpp and tests through VGFNeuralStatistics.h.
539+
// cppcheck-suppress unusedFunction
536540
std::string collect_vgf_neural_statistics_metadata(
537541
VkDevice device,
538542
const std::vector<VgfNeuralStatisticsSegmentContext>& segments) {
@@ -545,15 +549,19 @@ std::string collect_vgf_neural_statistics_metadata(
545549
collect_vgf_neural_statistics(device, segments));
546550
}
547551

552+
// Used by vgf_neural_statistics_test.cpp through VGFNeuralStatistics.h.
553+
// cppcheck-suppress unusedFunction
548554
void set_vgf_neural_statistics_collector_for_test(
549555
VgfNeuralStatisticsCollectorForTest collector) {
550556
test_collector_storage() = std::move(collector);
551557
}
552558

559+
// Used by vgf_neural_statistics_test.cpp through VGFNeuralStatistics.h.
560+
// cppcheck-suppress unusedFunction
553561
void reset_vgf_neural_statistics_collector_for_test() {
554562
test_collector_storage() = nullptr;
555563
}
556564

557565
} // namespace vgf
558566
} // namespace backends
559-
} // namespace executorch
567+
} // namespace executorch

‎backends/arm/scripts/banned_functions.json‎

Lines changed: 14 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -9,99 +9,45 @@
99
"replacements": ["fgets"]
1010
},
1111
{
12-
"names": ["memcpy"],
13-
"replacements": ["memcpy_s"]
12+
"names": ["atof"],
13+
"replacements": ["strtod"]
1414
},
1515
{
16-
"names": ["wmemcpy"],
17-
"replacements": ["wmemcpy_s"]
16+
"names": ["atoi", "atol", "atoll"],
17+
"replacements": ["strtol", "strtoll", "strtoul", "strtoull"]
1818
},
1919
{
20-
"names": ["memmove"],
21-
"replacements": ["memmove_s"]
20+
"names": ["rewind"],
21+
"replacements": ["See SEI CERT MSC24-C: https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/recommendations/miscellaneous-msc/msc24-c/"]
2222
},
2323
{
24-
"names": ["wmemmove"],
25-
"replacements": ["wmemmove_s"]
24+
"names": ["setbuf"],
25+
"replacements": ["setvbuf"]
2626
},
2727
{
2828
"names": ["readdir_r"],
2929
"replacements": ["readdir"]
3030
},
31-
{
32-
"names": ["scanf", "wscanf", "_tscanf", "sscanf", "swscanf", "_stscanf"],
33-
"replacements": ["fgets"]
34-
},
3531
{
3632
"names": [
3733
"strcat",
38-
"wcscat",
39-
"_tcscat",
40-
"_mbscat",
41-
"StrCat",
42-
"lstrcat",
43-
"lStrCatBuff",
44-
"_tccat",
45-
"_mbccat",
46-
"_ftcscat",
47-
"strncat",
48-
"wcsncat",
49-
"_tcsncat",
50-
"_mbsncat",
51-
"_mbsnbcat",
52-
"StrCatN",
53-
"StrNCat",
54-
"lstrncat",
55-
"lstrcatn"
34+
"wcscat"
5635
],
57-
"replacements": ["strcat_s", "strncat_s"]
36+
"replacements": ["See SEI CERT STR31-C: https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/rules/characters-and-strings-str/str31-c/"]
5837
},
5938
{
6039
"names": [
6140
"strcpy",
62-
"wcscpy",
63-
"_tcscpy",
64-
"_mbscpy",
65-
"StrCpy",
66-
"lstrcpy",
67-
"_tccpy",
68-
"_mbccpy",
69-
"_ftcscpy",
70-
"strncpy",
71-
"wcsncpy",
72-
"_tcsncpy",
73-
"_mbsncpy",
74-
"_mbsnbcpy",
75-
"StrCpyN",
76-
"StrNCpy",
77-
"lstrcpyn"
41+
"wcscpy"
7842
],
79-
"replacements": ["strcpy_s", "strncpy_s"]
80-
},
81-
{
82-
"names": ["strlen"],
83-
"replacements": ["strnlen_s"]
84-
},
85-
{
86-
"names": ["wcslen"],
87-
"replacements": ["wcsnlen_s"]
88-
},
89-
{
90-
"names": ["strtok", "_tcstok", "wcstok", "_mbstok"],
91-
"replacements": ["strtok_s"]
43+
"replacements": ["See SEI CERT STR31-C: https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/rules/characters-and-strings-str/str31-c/"]
9244
},
9345
{
9446
"names": [
95-
"wsprintf",
9647
"sprintf",
97-
"swprintf",
98-
"_stprintf",
99-
"wvsprintf",
100-
"vsprintf",
101-
"_vstprintf",
102-
"vswprintf"
48+
"vsprintf"
10349
],
104-
"replacements": ["snprintf", "snprintf_s"]
50+
"replacements": ["snprintf", "vsnprintf"]
10551
}
10652
]
10753
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
SPDX-FileCopyrightText: Copyright 2026 Arm Limited and/or its affiliates <open-source-office@arm.com>
22
SPDX-License-Identifier: MIT
33

4-
File copied from https://github.com/justinchuby/lintrunner-adapters/ which has an MIT license.
5-
File permalink: https://github.com/justinchuby/lintrunner-adapters/blob/772e5936d9b02814e29e12ca1355d33b029688c2/examples/adapters/cpp_banned_functions_linter/example_banned_functions.json
4+
Derived from the MIT-licensed example at:
5+
https://github.com/justinchuby/lintrunner-adapters/blob/772e5936d9b02814e29e12ca1355d33b029688c2/examples/adapters/cpp_banned_functions_linter/example_banned_functions.json
6+
7+
Modified for the ExecuTorch Arm backend.

0 commit comments

Comments
 (0)