From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7575F3858005; Mon, 25 Oct 2021 21:02:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7575F3858005 From: "drohr at jwdt dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/102937] New: Miscompilation with -O3 and aliasing of char* and size_t Date: Mon, 25 Oct 2021 21:02:08 +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: 11.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: drohr at jwdt dot org 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: Mon, 25 Oct 2021 21:02:08 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102937 Bug ID: 102937 Summary: Miscompilation with -O3 and aliasing of char* and size_t Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: drohr at jwdt dot org Target Milestone: --- Created attachment 51663 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D51663&action=3Dedit testcase The attached testcase miscompiles with GCC 11.2 when using -O3. It compiles correctly with -O3, and also with GCC 10.3 using -O3. For reference the cod= e is also here: https://godbolt.org/z/cjr584sMo The program prints a ptr twice, which should have been modified in between,= but this is not the case, thus it prints twice a nullptr: FOO 0x(nil) BAR 0x(nil) By either commenting in the printf in line 51 (or also by outcommenting the call to computePointerWithAlignment in line 50) the miscompilation disappea= rs, and the output is FOO 0x(nil) test 0x800 BAR 0x0x800=