work around GCC#61971 (spurious -Warray-bounds warnings) in folly::FixedString
authorEric Niebler <eniebler@fb.com>
Wed, 14 Dec 2016 20:21:25 +0000 (12:21 -0800)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Wed, 14 Dec 2016 20:33:02 +0000 (12:33 -0800)
commit6ed9b4c667bdba5ce0da3da165d4da5c42e0626f
treeb1e09e2f23939341deca89ecc8218aa8d32a5466
parent56ef367e4b0cf8fdb1265f0f6d9a40e7fe855f9a
work around GCC#61971 (spurious -Warray-bounds warnings) in folly::FixedString

Summary:
GCC has the temerity to insinuate that my code has out-of-array-bounds access. After cross-checking with clang and ubsan, reviewing the code, and running constexpr tests (for which out-of-range errors are caught at compile time), I can say with pretty high confidence that this is an instance of GCC#61971 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61971). Basically, the gcc-4 series is known to issue spurious -Warray-bounds warnings. The "fix" is to route internal accesses to some helper functions, for which -Warray-bounds has been suppressed.

User code that accesses elements with operator[] will still warn on out-of-bounds access. If this is a problem in practice, we can suppress the warning there, too. Trying this for now since it is less likely to hide real problems.

Reviewed By: yfeldblum

Differential Revision: D4317305

fbshipit-source-id: 7bf92f993ac1a29631463c582c1b64d76f755181
folly/FixedString.h
folly/test/FixedStringTest.cpp