public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "egallager 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: Tue, 14 Apr 2020 05:58:49 +0000	[thread overview]
Message-ID: <bug-81172-4-KxXvm5tKAP@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

Eric Gallager <egallager at gcc dot gnu.org> changed:

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

--- Comment #7 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #6)
> 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";
>       |            ^

I'd think breaking this into a separate sub-option as previously suggested
would still be useful; I can see people wanting other -Warray-bounds warnings
but not these, and vice versa

      parent reply	other threads:[~2020-04-14  5:58 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
2020-04-14  5:58 ` egallager at gcc dot gnu.org [this message]

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