Commit 6ed9b4c6 authored by Eric Niebler's avatar Eric Niebler Committed by Facebook Github Bot

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
parent 56ef367e
This diff is collapsed.
......@@ -640,6 +640,30 @@ TEST(FixedStringReverseIteratorTest, ConstexprReverseIteration) {
static_assert((alpha.rend() - 2) == (alpha.rbegin() + 24), "");
}
namespace GCC61971 {
// FixedString runs afoul of GCC #61971 (spurious -Warray-bounds)
// in optimized builds. The following test case triggers it for gcc-4.x.
// Test that FixedString suppresses the warning correctly.
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61971
constexpr auto xyz = folly::makeFixedString("xyz");
constexpr auto dot = folly::makeFixedString(".");
template <typename T1>
constexpr auto concatStuff(const T1& component) noexcept {
return xyz + dot + component;
}
constexpr auto co = folly::makeFixedString("co");
struct S {
std::string s{concatStuff(co)};
};
} // namespace GCC61971
TEST(FixedStringGCC61971, GCC61971) {
GCC61971::S s;
(void)s;
}
#include <folly/Range.h>
TEST(FixedStringConversionTest, ConversionToFollyRange) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment