public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/104800] New: reodering of potentially trapping operations and volatile stores
@ 2022-03-05 18:46 muecker at gwdg dot de
  2022-03-05 18:50 ` [Bug tree-optimization/104800] " muecker at gwdg dot de
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: muecker at gwdg dot de @ 2022-03-05 18:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104800
           Summary: reodering of potentially trapping operations and
                    volatile stores
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: muecker at gwdg dot de
  Target Milestone: ---

In the following example, a potentially trapping operation is moved before the
store to the volatile variable.  This can change observable behavior.  Because
division by zero is UB this is a correct optimization in C++ where UB is
allowed to affect previous observable behavior.  For C, I believe that this is
not allowed by the standard. In any case, it annoying (e.g. when debugging of
embedded devices) and dangerous (e.g. in device drivers or when controling
machines) and best avoided.


volatile int x;

int foo(int a, int b, _Bool store_to_x)
{
  if (!store_to_x)
    return a / b;
  x = b;
  return a / b;
}

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

end of thread, other threads:[~2022-03-09  9:10 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-05 18:46 [Bug tree-optimization/104800] New: reodering of potentially trapping operations and volatile stores muecker at gwdg dot de
2022-03-05 18:50 ` [Bug tree-optimization/104800] " muecker at gwdg dot de
2022-03-05 21:07 ` pinskia at gcc dot gnu.org
2022-03-06  5:04 ` [Bug middle-end/104800] " paulmckrcu at gmail dot com
2022-03-06  6:46 ` muecker at gwdg dot de
2022-03-06  6:54 ` muecker at gwdg dot de
2022-03-07  8:52 ` rguenth at gcc dot gnu.org
2022-03-07 17:47 ` paulmckrcu at gmail dot com
2022-03-08 20:27 ` muecker at gwdg dot de
2022-03-09  7:26 ` rguenth at gcc dot gnu.org
2022-03-09  7:29 ` rguenth at gcc dot gnu.org
2022-03-09  7:40 ` muecker at gwdg dot de
2022-03-09  7:42 ` muecker at gwdg dot de
2022-03-09  7:52 ` rguenther at suse dot de
2022-03-09  8:06 ` rguenther at suse dot de
2022-03-09  9:05 ` muecker at gwdg dot de
2022-03-09  9:10 ` muecker at gwdg 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).