https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62006
Bug ID: 62006 Summary: Bad code generation with -O3 (possibly due to -ftree-partial-pre) Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: tkoeppe at google dot com Created attachment 33231 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33231&action=edit Demonstrates bad code generation with -O3 I was writing some code to demonstrate custom allocators with fancy pointers. While testing it with GCC, I noticed memory corruption when compiling with -O3. Jonathan Wakely had a quick look and narrowed it down to "-O2 -ftree-partial-pre"; with just "-O2" the code works. I don't have any insights in the problem, so I'm just attaching the full code. You can tell that it's broken by passing the program through valgrind, or simply by noting that it prints all container elements as zero, rather than their actual values. (Incidentally, I believe there's a similar problem in Clang: http://llvm.org/bugs/show_bug.cgi?id=20524)