public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/103830] New: volatile optimized away
@ 2021-12-26 10:00 bernd.edlinger at hotmail dot de
  2021-12-26 10:10 ` [Bug rtl-optimization/103830] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: bernd.edlinger at hotmail dot de @ 2021-12-26 10:00 UTC (permalink / raw)
  To: gcc-bugs

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

            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 <http://www.gnu.org/licenses/>.  */

/* PR 25987 */
struct MyClass;
struct ptr {
    MyClass* get() { return t; }     /* line 21 */
    MyClass* t;
};
struct MyClass { void call(); };
void MyClass::call() {
    *(volatile char*)(nullptr) = 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.

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

end of thread, other threads:[~2022-01-28 12:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-26 10:00 [Bug rtl-optimization/103830] New: volatile optimized away bernd.edlinger at hotmail dot de
2021-12-26 10:10 ` [Bug rtl-optimization/103830] " pinskia at gcc dot gnu.org
2021-12-26 10:19 ` [Bug ipa/103830] [12 Regression] null pointer access optimized away by removing function call at -Og pinskia at gcc dot gnu.org
2021-12-27 16:20 ` jakub at gcc dot gnu.org
2022-01-04 13:35 ` rguenth at gcc dot gnu.org
2022-01-04 14:52 ` hubicka at kam dot mff.cuni.cz
2022-01-28 12:02 ` rguenth at gcc dot gnu.org
2022-01-28 12:04 ` rguenth at gcc dot gnu.org
2022-01-28 12:06 ` rguenth at gcc dot gnu.org
2022-01-28 12:08 ` bernd.edlinger at hotmail dot de

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).