public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/59564] New: False positive array -Warray-bounds check with -O2
@ 2013-12-19 19:43 egor_suvorov at mail dot ru
  2013-12-20 10:30 ` [Bug tree-optimization/59564] " rguenth at gcc dot gnu.org
  2021-08-03 19:02 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: egor_suvorov at mail dot ru @ 2013-12-19 19:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59564

            Bug ID: 59564
           Summary: False positive array -Warray-bounds check with -O2
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: egor_suvorov at mail dot ru

Created attachment 31482
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31482&action=edit
Output of gcc with '-v -save-temps'

Here's a full code:

int arr[1];
int n = 0;

int main() {
  if (n <= 0) n = 0;
  arr[n] = 0;
  if (n <= 0) n = 0;
  return 0;
}

If you compile this code with '-O2 -Warray-bounds', gcc produces warning, which
is obviously incorrect. You can also change inequality checks to >= and you'll
get another similar warning.

I've checked it on mingw 4.8.1, mingw 4.7.2 and on debian gcc 4.7.2 - works
everywhere. You can also save this file as .cpp and compile with g++ - bug
persists.


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

* [Bug tree-optimization/59564] False positive array -Warray-bounds check with -O2
  2013-12-19 19:43 [Bug c/59564] New: False positive array -Warray-bounds check with -O2 egor_suvorov at mail dot ru
@ 2013-12-20 10:30 ` rguenth at gcc dot gnu.org
  2021-08-03 19:02 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-12-20 10:30 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59564

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-12-20
          Component|c                           |tree-optimization
            Version|unknown                     |4.9.0
     Ever confirmed|0                           |1
      Known to fail|                            |4.8.2, 4.9.0

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
DOM optimizes this to

  if (n <= 0)
    {
      n = 0;
      arr[0] = 0;
    }
  else
    arr[n] = 0;

after which value-range propagation warns for the arr[n] on the else
branch because there n >= 1 and thus the access is out-of-bounds.

Fixing the obfuscation by doing

  if (n < 0) n = 0;

instead of

  if (n <= 0) n = 0;

fixes the warning.

The warning is basically that n is not constrained to be < 1 which is
of course kind-of-useless.  We don't warn for a plain arr[n] either.
But as you give VRP a half-useful range you make it emit the warning.

Common to these kind of "bogus" warnings is that we have duplicated the
memory access and warn about the "bad" half of it.  But we have no way
of tracking whether there are now two pieces instead of just one ...
(apart from maybe using source location info and making sure that VRP
computes the same "warning" for equal source location accesses).


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

* [Bug tree-optimization/59564] False positive array -Warray-bounds check with -O2
  2013-12-19 19:43 [Bug c/59564] New: False positive array -Warray-bounds check with -O2 egor_suvorov at mail dot ru
  2013-12-20 10:30 ` [Bug tree-optimization/59564] " rguenth at gcc dot gnu.org
@ 2021-08-03 19:02 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-03 19:02 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |4.9.3
         Resolution|---                         |FIXED

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So this was fixed by r5-6842 which was backported for GCC 4.9.3 also.

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

end of thread, other threads:[~2021-08-03 19:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-19 19:43 [Bug c/59564] New: False positive array -Warray-bounds check with -O2 egor_suvorov at mail dot ru
2013-12-20 10:30 ` [Bug tree-optimization/59564] " rguenth at gcc dot gnu.org
2021-08-03 19:02 ` pinskia 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).