public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/94374] New: modification of constant scalars sometimes eliminated, sometimes not
@ 2020-03-27 23:30 msebor at gcc dot gnu.org
  2020-03-27 23:32 ` [Bug tree-optimization/94374] " msebor at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-03-27 23:30 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94374
           Summary: modification of constant scalars sometimes eliminated,
                    sometimes not
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Similar to pr94313, the test case below shows that GCC silently eliminates some
statements that modify const scalars while emitting others.  As in the other
report, while this isn't strictly wrong (the modification is undefined), doing
so silently, without a warning, is unhelpful.  It prevents the bugs from
getting fixed, and leads to inconsistent results at runtime.

At a minimum, GCC should diagnose all these cases before removing them. 
Preferably, however, it should treat all of them the same (i.e., either remove
all of them or none), ideally leaving the choice of which up to the user.  The
three alternative strategies that have been suggested as most useful are:
either a) removal, or b) insertion of __builtin_trap, or c) insertion of
__builtin_unreachable.

$ cat d.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout d.c
extern const int a;

int fa (void)
{ 
  int *p = (int*)&a;
  ++*p;                // not eliminated
  return *p;           // not folded
}

static const int b;

int fb (void)
{
  int *p = (int*)&b;
  ++*p;                // eliminated
  return *p;           // folded to zero
}

int fc (void)
{ 
  static const int c;
  int *p = (int*)&c;
  ++*p;                // eliminated
  return *p;           // folded to zero
}

int fd (void)
{
  const int d = 0;
  int *p = (int*)&d;
  ++*p;                // not eliminated
  return *p;           // folded to 1
}


;; Function fa (fa, funcdef_no=0, decl_uid=1931, cgraph_uid=1, symbol_order=0)

fa ()
{
  int _1;
  int _2;

  <bb 2> [local count: 1073741824]:
  _1 = a;
  _2 = _1 + 1;
  a = _2;
  return _2;

}



;; Function fb (fb, funcdef_no=1, decl_uid=1936, cgraph_uid=2, symbol_order=2)

fb ()
{
  <bb 2> [local count: 1073741824]:
  return 0;

}



;; Function fc (fc, funcdef_no=5, decl_uid=1940, cgraph_uid=3, symbol_order=3)

fc ()
{
  <bb 2> [local count: 1073741824]:
  return 0;

}



;; Function fd (fd, funcdef_no=3, decl_uid=1945, cgraph_uid=4, symbol_order=4)

fd ()
{
  <bb 2> [local count: 1073741824]:
  return 1;

}

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

* [Bug tree-optimization/94374] modification of constant scalars sometimes eliminated, sometimes not
  2020-03-27 23:30 [Bug tree-optimization/94374] New: modification of constant scalars sometimes eliminated, sometimes not msebor at gcc dot gnu.org
@ 2020-03-27 23:32 ` msebor at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-03-27 23:32 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=94313,
                   |                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=90404

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
As in pr94313, the intent of this report is simply to document the cases where
the removal of these modifying statements is making their reliable detection
(requested in pr90404) difficult.

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

end of thread, other threads:[~2020-03-27 23:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-27 23:30 [Bug tree-optimization/94374] New: modification of constant scalars sometimes eliminated, sometimes not msebor at gcc dot gnu.org
2020-03-27 23:32 ` [Bug tree-optimization/94374] " msebor at gcc dot gnu.org

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