public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "david at westcontrol dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/105523] Wrong warning array subscript [0] is outside array bounds
Date: Tue, 25 Apr 2023 16:45:20 +0000	[thread overview]
Message-ID: <bug-105523-4-qVtfIWHLqA@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-105523-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #25 from David Brown <david at westcontrol dot com> ---
(In reply to Andrew Pinski from comment #24)
> (In reply to LIU Hao from comment #22)
> > Yes, GCC should be told to shut up about dereferencing artificial address
> > values.
> 
> NO.
> Take:
> ```
> static inline int f(int *a)
> {
>   return a[10];
> }
> 
> int g()
> {
>   return f(0);
> }
> ```
> The warning is there for the above case really (and similar ones with struct
> offsets). Where you originally have a null pointer and have an offset from
> there; by the time the warning happens, the IR does not know if it was
> originally from an offset of a null pointer or if the value was written in.
> The paramater is there to "tune" the heurstic to figure out if it is null
> pointer deference or if it is some real (HW) address. Maybe
> -fno-delete-null-pointer-checks should imply --param=min-pagesize=0, though
> some folks want the warning indepdent of trying to delete null pointer
> checks.

It is worth noting, I think, that although on a target like the AVR (and most
embedded systems without an MMU) the address 0 is a real part of memory, and
can really be read and/or written, any code that tries to dereference a 0
pointer is almost always wrong.  I don't want gcc to consider 0 as an
acceptable address on these targets - I want it to warn me if it sees a null
pointer dereference.  If I really want to target address 0, as I might
occasionally do, I'll use a pointer to volatile - /then/ I'd like gcc to
believe me without question.

I don't know if every embedded developer feels the same way.  (Georg-Johann
could chime in with his opinion.)

  parent reply	other threads:[~2023-04-25 16:45 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-08 12:12 [Bug c++/105523] New: " klaus.doldinger64 at googlemail dot com
2022-05-08 19:53 ` [Bug target/105523] " pinskia at gcc dot gnu.org
2022-05-09  4:00 ` klaus.doldinger64 at googlemail dot com
2022-05-09  4:54 ` klaus.doldinger64 at googlemail dot com
2022-05-09  6:59 ` klaus.doldinger64 at googlemail dot com
2022-05-11 11:50 ` rudi at heitbaum dot com
2022-10-21  5:57 ` lh_mouse at 126 dot com
2022-11-23 17:49 ` gjl at gcc dot gnu.org
2022-11-23 17:53 ` pinskia at gcc dot gnu.org
2022-11-23 17:56 ` pinskia at gcc dot gnu.org
2022-11-23 18:04 ` lh_mouse at 126 dot com
2022-11-23 18:07 ` pinskia at gcc dot gnu.org
2022-11-23 18:11 ` konrad at silmor dot de
2022-11-24  3:35 ` lh_mouse at 126 dot com
2022-12-07  6:32 ` ahmad at a3f dot at
2023-01-22 23:44 ` westfw at westfw dot info
2023-03-31 10:02 ` dcrocker at eschertech dot com
2023-03-31 20:32 ` pinskia at gcc dot gnu.org
2023-04-24 15:21 ` david at westcontrol dot com
2023-04-24 18:41 ` gjl at gcc dot gnu.org
2023-04-25  7:18 ` david at westcontrol dot com
2023-04-25  7:30 ` david at westcontrol dot com
2023-04-25  7:30 ` lh_mouse at 126 dot com
2023-04-25  7:46 ` david at westcontrol dot com
2023-04-25 16:30 ` pinskia at gcc dot gnu.org
2023-04-25 16:45 ` david at westcontrol dot com [this message]
2023-04-25 16:57 ` klaus.doldinger64 at googlemail dot com
2023-04-25 16:58 ` klaus.doldinger64 at googlemail dot com
2023-04-25 17:04 ` pinskia at gcc dot gnu.org
2023-04-25 19:02 ` gjl at gcc dot gnu.org
2023-04-25 19:07 ` konrad at silmor dot de
2023-04-28  5:17 ` lh_mouse at 126 dot com
2023-04-28  5:25 ` pinskia at gcc dot gnu.org
2023-06-19  8:23 ` cvs-commit at gcc dot gnu.org
2023-08-01 13:45 ` gjl at gcc dot gnu.org
2023-08-09 18:53 ` gjl at gcc dot gnu.org
2024-02-12 17:08 ` cvs-commit at gcc dot gnu.org
2024-02-12 17:10 ` gjl 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-105523-4-qVtfIWHLqA@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).