Skip to content

Commit 411061f

Browse files
lucylqGithub Executorch
andauthored
Fix size test build on gcc11 (#17905)
### Summary Fix size-test on gcc11 (not a binary size improvement) It fails with stringop-overread from flatbuffer. gcc-9 doesn't have this and doesn't throw error. ``` In static member function ‘static constexpr std::size_t std::char_traits<char>::length(const char_type*)’, inlined from ‘constexpr std::basic_string_view<_CharT, _Traits>::basic_string_view(const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>]’ at /usr/include/c++/11/string_view:132:35, inlined from ‘executorch::runtime::Result<void*> executorch::runtime::deserialization::getTensorDataPtr(const executorch_flatbuffer::Tensor*, const executorch::runtime::Program*, size_t, executorch::runtime::HierarchicalAllocator*, const executorch::runtime::NamedDataMap*, executorch::runtime::Span<executorch::runtime::deserialization::NamedData>)’ at /data/users/lfq/binary-size/executorch/runtime/executor/tensor_parser_exec_aten.cpp:218:41: /usr/include/c++/11/bits/char_traits.h:399:32: error: ‘long unsigned int __builtin_strlen(const char*)’ reading 1 or more bytes from a region of size 0 [-Werror=stringop-overread] 399 | return __builtin_strlen(__s); | ~~~~~~~~~~~~~~~~^~~~~ In file included from /data/users/lfq/binary-size/executorch/../executorch/runtime/executor/tensor_parser.h:21, from /data/users/lfq/binary-size/executorch/runtime/executor/tensor_parser_exec_aten.cpp:9: /data/users/lfq/binary-size/executorch/cmake-out/schema/include/executorch/schema/program_generated.h: In function ‘executorch::runtime::Result<void*> executorch::runtime::deserialization::getTensorDataPtr(const executorch_flatbuffer::Tensor*, const executorch::runtime::Program*, size_t, executorch::runtime::HierarchicalAllocator*, const executorch::runtime::NamedDataMap*, executorch::runtime::Span<executorch::runtime::deserialization::NamedData>)’: /data/users/lfq/binary-size/executorch/cmake-out/schema/include/executorch/schema/program_generated.h:568:8: note: at offset 5 into source object ‘executorch_flatbuffer::ExtraTensorInfo::<anonymous>’ of size 1 568 | struct ExtraTensorInfo FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { ``` ### Test plan Flatbuffer should be ok - add -Wno-stringop-overread to suppress the error. Use pragma because adding it in CXX_ARGS causes a failure, as gcc-9 doesn't recognize it and -Werror is enabled. size results after stripping ``` sh test/build_size_test.sh (executorch) [lfq@devvm11764.nha0 /data/users/lfq/binary-size/executorch (binary-size)]$ ls -la cmake-out/test/size_test_all_ops -rwxr-xr-x 1 lfq users 1670416 Mar 4 22:37 cmake-out/test/size_test_all_ops (executorch) [lfq@devvm11764.nha0 /data/users/lfq/binary-size/executorch (binary-size)]$ ls -la cmake-out/test/size_test -rwxr-xr-x 1 lfq users 56240 Mar 4 22:38 cmake-out/test/size_test ``` --------- Co-authored-by: Github Executorch <github_executorch@arm.com>
1 parent be6b986 commit 411061f

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

runtime/executor/tensor_parser_exec_aten.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ NamedData* get_data_by_key(const char* key, Span<NamedData> entries) {
159159
return nullptr;
160160
}
161161

162+
// Suppress a GCC 11 false positive -Wstringop-overread triggered by
163+
// flatbuffers' GetPointer inlining into string_view construction.
164+
// Guarded to GCC >= 11 since the warning doesn't exist on older GCC or Clang.
165+
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 11
166+
#pragma GCC diagnostic push
167+
#pragma GCC diagnostic ignored "-Wstringop-overread"
168+
#endif
169+
162170
ET_NODISCARD Result<void*> getTensorDataPtr(
163171
const executorch_flatbuffer::Tensor* s_tensor,
164172
const Program* program,
@@ -259,6 +267,10 @@ ET_NODISCARD Result<void*> getTensorDataPtr(
259267
}
260268
}
261269

270+
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 11
271+
#pragma GCC diagnostic pop
272+
#endif
273+
262274
} // namespace deserialization
263275
} // namespace ET_RUNTIME_NAMESPACE
264276
} // namespace executorch

0 commit comments

Comments
 (0)