public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/94675] [9 regression] -Warray-bounds false positive with -O2
Date: Mon, 20 Apr 2020 22:16:33 +0000	[thread overview]
Message-ID: <bug-94675-4-YfzU9ynG2o@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94675-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The false positive is not due a shortcoming of the warning but rather due to
GCC not having a sufficiently sophisticated analysis of relationships of
pointers into the same objects.  The same warning (and probably a numbers as
well) can be reproduced with a simpler example.

$ cat pr94675.c && gcc -O2 -S -Wall -fdump-tree-vrp=/dev/stdout pr94675.c
unsigned char c, n;

int f (void)
{
  if (n <= 7) return 0;

  unsigned char *p = &c, *q = p + n;

  if (q - p <= 7)   // not eliminated
    return 0;

  return p[7];      // spurious -Warray-bounds
}

;; Function f (f, funcdef_no=0, decl_uid=1932, cgraph_uid=1, symbol_order=2)

;; 1 loops found
;;
;; Loop 0
;;  header 0, latch 1
;;  depth 0, outer -1
;;  nodes: 0 1 2 3 4
;; 2 succs { 4 3 }
;; 3 succs { 4 }
;; 4 succs { 1 }

Value ranges after VRP:

n.0_1: unsigned char VARYING
_2: unsigned char VARYING
_3: int [0, 255]
_5: int [0, 255]


pr94675.c: In function ‘f’:
pr94675.c:12:11: warning: array subscript 7 is outside array bounds of
‘unsigned char[1]’ [-Warray-bounds]
   12 |   return p[7];
      |          ~^~~
pr94675.c:1:15: note: while referencing ‘c’
    1 | unsigned char c, n;
      |               ^
f ()
{
  unsigned char n.0_1;
  unsigned char _2;
  int _3;
  int _5;

  <bb 2> [local count: 1073741824]:
  n.0_1 = n;
  if (n.0_1 <= 7)
    goto <bb 4>; [34.00%]
  else
    goto <bb 3>; [66.00%]

  <bb 3> [local count: 708669601]:
  _2 = MEM[(unsigned char *)&c + 7B];
  _5 = (int) _2;

  <bb 4> [local count: 1073741824]:
  # _3 = PHI <0(2), _5(3)>
  return _3;

}



;; Function f (f, funcdef_no=0, decl_uid=1932, cgraph_uid=1, symbol_order=2)

;; 1 loops found
;;
;; Loop 0
;;  header 0, latch 1
;;  depth 0, outer -1
;;  nodes: 0 1 2 3 4
;; 2 succs { 4 3 }
;; 3 succs { 4 }
;; 4 succs { 1 }

Value ranges after VRP:

n.0_1: unsigned char VARYING
_2: unsigned char VARYING
_3: int [0, 255]
_5: int [0, 255]


f ()
{
  unsigned char n.0_1;
  unsigned char _2;
  int _3;
  int _5;

  <bb 2> [local count: 1073741824]:
  n.0_1 = n;
  if (n.0_1 <= 7)
    goto <bb 4>; [34.00%]
  else
    goto <bb 3>; [66.00%]

  <bb 3> [local count: 708669601]:
  _2 = MEM[(unsigned char *)&c + 7B];
  _5 = (int) _2;

  <bb 4> [local count: 1073741824]:
  # _3 = PHI <_5(3), 0(2)>
  return _3;

}

  reply	other threads:[~2020-04-20 22:16 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-20 19:42 [Bug tree-optimization/94675] New: " chantry.xavier at gmail dot com
2020-04-20 22:16 ` msebor at gcc dot gnu.org [this message]
2020-04-21  6:51 ` [Bug tree-optimization/94675] " chantry.xavier at gmail dot com
2020-04-21  7:04 ` marxin at gcc dot gnu.org
2020-04-21  7:46 ` rguenth at gcc dot gnu.org
2020-04-21  7:58 ` [Bug tree-optimization/94675] [9/10 " rguenth at gcc dot gnu.org
2020-04-21  7:59 ` jakub at gcc dot gnu.org
2020-04-21  8:06 ` [Bug tree-optimization/94675] [9/10 regression] -Warray-bounds false positive with -O2 since r9-1948 jakub at gcc dot gnu.org
2020-04-21 14:03 ` law at redhat dot com
2020-04-21 14:18 ` rguenther at suse dot de
2020-04-21 14:43 ` law at redhat dot com
2020-04-21 14:57 ` rguenther at suse dot de
2020-04-21 14:58 ` msebor at gcc dot gnu.org
2020-04-21 19:14 ` law at redhat dot com
2020-04-21 19:16 ` law at redhat dot com
2020-04-21 20:10 ` law at redhat dot com
2020-04-21 21:00 ` msebor at gcc dot gnu.org
2020-04-22  6:34 ` rguenther at suse dot de
2020-04-24  7:48 ` chantry.xavier at gmail dot com
2020-04-24 15:16 ` msebor at gcc dot gnu.org
2020-04-30 13:12 ` chantry.xavier at gmail dot com
2021-06-01  8:17 ` [Bug tree-optimization/94675] [9/10/11/12 " rguenth at gcc dot gnu.org
2021-09-06 11:25 ` pinskia at gcc dot gnu.org
2022-03-16 11:09 ` chantry.xavier at gmail dot com
2022-03-16 13:24 ` rguenth at gcc dot gnu.org
2022-05-27  9:42 ` [Bug tree-optimization/94675] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:40 ` jakub at gcc dot gnu.org
2023-05-14 21:25 ` [Bug tree-optimization/94675] [10/11/12/13/14 " pinskia at gcc dot gnu.org
2023-07-07 10:37 ` [Bug tree-optimization/94675] [11/12/13/14 " rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-94675-4-YfzU9ynG2o@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).