Skip to content

Commit 5405d02

Browse files
Krishna Paifacebook-github-bot
authored andcommitted
fix: Spurious compiler error due to deep inlining (facebookincubator#16002)
Summary: Ubuntu release build gives the following error due to GCC's spurious deep inlining optimization when inlining creation of StringViews : ``` /usr/include/x86_64-linux-gnu/bits/string_fortified.h:29:33: error: ‘void* __builtin___memcpy_chk(void*, const void*, long unsigned int, long unsigned int)’ writing 13 or more bytes into a region of size 12 overflows the destination [-Werror=stringop-overflow=] 29 | return __builtin___memcpy_chk (__dest, __src, __len, | ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ 30 | __glibc_objsize0 (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` This fixes it by letting the compiler know that its not possible to have length > 12 in the inlining case. Fixes facebookincubator#15245 Differential Revision: D90620860
1 parent d11f8e4 commit 5405d02

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

velox/type/StringView.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,17 @@ struct StringView {
9292
// small string: inlined. Zero the last 8 bytes first to allow for whole
9393
// word comparison.
9494
value_.data = nullptr;
95+
#ifdef __GNUC__
96+
// Use asm volatile to prevent GCC's interprocedural analysis from
97+
// incorrectly concluding that size could exceed kInlineSize. This is a
98+
// workaround for a false positive -Wstringop-overflow warning when GCC
99+
// cannot prove the size constraint through deep template inlining.
100+
auto sz = static_cast<size_t>(size_);
101+
asm volatile("" : "+r"(sz));
102+
memcpy(prefix_, data, sz);
103+
#else
95104
memcpy(prefix_, data, size_);
105+
#endif
96106
} else {
97107
// large string: store pointer
98108
memcpy(prefix_, data, kPrefixSize);

0 commit comments

Comments
 (0)