From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DC314388C024; Thu, 11 Jun 2020 11:45:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC314388C024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1591875904; bh=ftgwyqF9g4KlrUP8LiwiMuvWQxWx3Oi79aLs9dkcf/A=; h=From:To:Subject:Date:From; b=d1iMFGHv57DKMXoa6hHB0K+sOuykMnFmLA9tgDM1dsRAd9xLX4/ForeUHkmsSXCcz lAQ6vdN0pCmcRo0mg9YRDttjfXesX1y0PYpxNVLWnv42fM0818nq/0susJq9eRTCHJ IR6CW/aMGpcZorVLE9iusnndm6FCnWj3CVsagUlk= From: "officesamurai at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/95638] New: Legit-looking code doesn't work with -O2 Date: Thu, 11 Jun 2020 11:45:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: officesamurai at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Jun 2020 11:45:05 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95638 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=3D48718&action=3Dedit 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 typ= e 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 accor= ding to [basic.life] (because "...using the pointer as if the pointer were of ty= pe void*, is well-defined"). ------------------------ $ g++-10.1.0 -v Using built-in specs. COLLECT_GCC=3Dg++-10.1.0 COLLECT_LTO_WRAPPER=3D/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=3D/home/brd/soft/gcc-10.1.0 Thread model: posix Supported LTO compression algorithms: zlib gcc version 10.1.0 (GCC)=20 $ g++-10.1.0 -O2 gcc10_aliasing_issue.cpp -o test -std=3Dc++14 && ./test Null!!! $ g++-10.1.0 -O2 -fno-strict-aliasing gcc10_aliasing_issue.cpp -o test -std=3Dc++14 && ./test OK ------------------------ P.S. The same code works fine with GCC 9 and earlier versions.=