From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4C3503858D39; Sun, 26 Dec 2021 10:00:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C3503858D39 From: "bernd.edlinger at hotmail dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/103830] New: volatile optimized away Date: Sun, 26 Dec 2021 10:00:14 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bernd.edlinger at hotmail dot de 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 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: Sun, 26 Dec 2021 10:00:14 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103830 Bug ID: 103830 Summary: volatile optimized away Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: bernd.edlinger at hotmail dot de Target Milestone: --- the following test case is intentionally writing at address 0, it is IMHO invalid to optimize it away (at -Og): $ cat empty-inline.cc /* This testcase is part of GDB, the GNU debugger. Copyright 2021 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* PR 25987 */ struct MyClass; struct ptr { MyClass* get() { return t; } /* line 21 */ MyClass* t; }; struct MyClass { void call(); }; void MyClass::call() { *(volatile char*)(nullptr) =3D 1; /* line 26 */ } static void intermediate(ptr p) { p.get()->call(); /* line 29 */ } int main() { intermediate(ptr{new MyClass}); } /* EOF */ previously this used to SIGSEGV in line 26, but no longer with git master from December 18th at least. I think it is rather common to have something at address zero, for instance interrupt tables or device registers, and therefore it's not OK to optimize those volatile accesses away.=