public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95638] New: Legit-looking code doesn't work with -O2
@ 2020-06-11 11:45 officesamurai at gmail dot com
  2020-06-11 12:08 ` [Bug c++/95638] " jakub at gcc dot gnu.org
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: officesamurai at gmail dot com @ 2020-06-11 11:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95638

            Bug ID: 95638
           Summary: Legit-looking code doesn't work with -O2
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: officesamurai at gmail dot com
  Target Milestone: ---

Created attachment 48718
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48718&action=edit
The failing code

The attached code produces wrong result when build with -O2 and without
-fno-strict-aliasing, but I don't believe it does anything illegal. The only
fishy thing it does is creating a pointer to T before an object of that type is
constructed at that location (in Storage::Storage and Storage::push_back), but
the pointer is just passed to the placement new, which should be fine according
to [basic.life] (because "...using the pointer as if the pointer were of type
void*, is well-defined").

------------------------
$ g++-10.1.0 -v
Using built-in specs.
COLLECT_GCC=g++-10.1.0
COLLECT_LTO_WRAPPER=/home/brd/soft/gcc-10.1.0/libexec/gcc/x86_64-pc-linux-gnu/10.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/brd/soft/gcc-10.1.0
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.1.0 (GCC) 

$ g++-10.1.0 -O2 gcc10_aliasing_issue.cpp -o test -std=c++14 && ./test
Null!!!

$ g++-10.1.0 -O2 -fno-strict-aliasing gcc10_aliasing_issue.cpp -o test
-std=c++14 && ./test
OK
------------------------

P.S. The same code works fine with GCC 9 and earlier versions.

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2021-03-27  2:44 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-11 11:45 [Bug c++/95638] New: Legit-looking code doesn't work with -O2 officesamurai at gmail dot com
2020-06-11 12:08 ` [Bug c++/95638] " jakub at gcc dot gnu.org
2020-06-11 12:12 ` marxin at gcc dot gnu.org
2020-06-11 12:23 ` jakub at gcc dot gnu.org
2020-06-11 15:40 ` redi at gcc dot gnu.org
2020-06-12  1:17 ` amker at gcc dot gnu.org
2020-06-12  7:20 ` [Bug c++/95638] [10/11 Regression] " rguenth at gcc dot gnu.org
2020-06-14  0:47 ` amker at gcc dot gnu.org
2020-06-20  7:56 ` [Bug tree-optimization/95638] " cvs-commit at gcc dot gnu.org
2020-06-29 10:07 ` jakub at gcc dot gnu.org
2020-06-29 12:10 ` amker at gcc dot gnu.org
2020-07-09 11:47 ` rguenth at gcc dot gnu.org
2020-07-09 11:48 ` [Bug tree-optimization/95638] [10 " rguenth at gcc dot gnu.org
2020-07-10  3:59 ` cvs-commit at gcc dot gnu.org
2020-07-10  4:12 ` cvs-commit at gcc dot gnu.org
2020-07-23  6:51 ` rguenth at gcc dot gnu.org
2020-07-23  7:11 ` amker at gcc dot gnu.org
2021-03-27  2:44 ` amker at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).