This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/71002] New: [6 Regression] -fstrict-aliasing breaks Boost's short string optimization implementation
- From: "tavianator at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 07 May 2016 19:53:59 +0000
- Subject: [Bug middle-end/71002] New: [6 Regression] -fstrict-aliasing breaks Boost's short string optimization implementation
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71002
Bug ID: 71002
Summary: [6 Regression] -fstrict-aliasing breaks Boost's short
string optimization implementation
Product: gcc
Version: 6.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: tavianator at gmail dot com
Target Milestone: ---
Created attachment 38438
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38438&action=edit
Reduced test case
(This is the miscompilation I reported seeing in PR70054. I have a reduced
test case for it now.)
Since GCC 6, the following simple use of boost::container::string is broken:
$ cat foo.cpp
#include <boost/container/string.hpp>
#include <cstdlib>
#include <utility>
using boost::container::string;
struct foo
{
__attribute__((noinline))
foo(string str)
: m_str{std::move(str)},
m_len{m_str.length()}
{ }
string m_str;
std::size_t m_len;
};
int main() {
foo f{"the quick brown fox jumps over the lazy dog"};
if (f.m_len == 0) {
std::abort();
}
return 0;
}
$ g++ -O2 -Wall foo.cpp -o foo && ./foo
[1] 12277 abort (core dumped) ./foo
It works with -fno-strict-aliasing. I reduced the problem to the attached
standalone test case. Boost's code doesn't seem to be 100% compliant, but the
worst thing it does is access a non-active union member (the is_short
bitfield). As far as I know, GCC permits that as an extension.