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 middle-end/81172] Expected new warning option -Warray-bounds-pointer-arithmetic
Date: Mon, 13 Apr 2020 20:27:13 +0000	[thread overview]
Message-ID: <bug-81172-4-PwyxqV5XbI@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-81172-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |10.0
         Resolution|---                         |FIXED
             Blocks|                            |56456
             Status|NEW                         |RESOLVED

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
For the slightly modified test case GCC 10 issues the expected warnings in the
expected cases (i.e., unless the code is removed as unused, etc.)  So I think
this can be resolved as fixed.  (There are plenty of other cases that still
aren't diagnosed; please open new bugs for those if they aren't already being
tracked under pr56456).

$ cat pr81172.c && gcc -O2 -S -Wall pr81172.c

int a[] = {1,2,3,4};

int* f (void)
{
  int *p = a + 5;
  return p;
}

const char s[] = "aaa", t[] = "bbbbb";

const char* g (void)
{
  const char *p = s + __builtin_strlen (t);
  return p;
}

const char* h (void)
{
  return s + 'c';
}
pr81172.c: In function ‘f’:
pr81172.c:5:8: warning: array subscript 5 is outside array bounds of ‘int[4]’
[-Warray-bounds]
    5 |   int *p = a + 5;
      |        ^
pr81172.c:1:5: note: while referencing ‘a’
    1 | int a[] = {1,2,3,4};
      |     ^
pr81172.c: In function ‘g’:
pr81172.c:13:15: warning: array subscript 5 is outside array bounds of ‘const
char[4]’ [-Warray-bounds]
   13 |   const char *p = s + __builtin_strlen (t);
      |               ^
pr81172.c:9:12: note: while referencing ‘s’
    9 | const char s[] = "aaa", t[] = "bbbbb";
      |            ^
pr81172.c: In function ‘h’:
pr81172.c:19:12: warning: array subscript 99 is outside array bounds of ‘const
char[4]’ [-Warray-bounds]
   19 |   return s + 'c';
      |          ~~^~~~~
pr81172.c:9:12: note: while referencing ‘s’
    9 | const char s[] = "aaa", t[] = "bbbbb";
      |            ^


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56456
[Bug 56456] [meta-bug] bogus/missing -Warray-bounds

       reply	other threads:[~2020-04-13 20:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-81172-4@http.gcc.gnu.org/bugzilla/>
2020-04-13 20:27 ` msebor at gcc dot gnu.org [this message]
2020-04-14  5:58 ` egallager 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-81172-4-PwyxqV5XbI@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).