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: Mon, 24 Apr 2023 15:21:14 +0000	[thread overview]
Message-ID: <bug-105523-4-zfjdAIseJf@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

David Brown <david at westcontrol dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |david at westcontrol dot com

--- Comment #18 from David Brown <david at westcontrol dot com> ---
This issue does not appear to be related to any particular backend.

Changing the initial code to remove the volatile :

void m(void) {
     uint8_t * ptr2 = ( uint8_t*)(0x0030);
    *ptr2 = 0xd8;
}

gives a warning in gcc 11 as well - "warning: writing 1 byte into a region of
size 0".  (gcc 12 and 13 give the "array subscript [0] is outside array bounds"
warning.)


It is standard practice in embedded development to cast an integer value (often
a compile-time constant, but not always) to a pointer and use that to access
memory-mapped registers or other data at fixed addresses.  Typically the
pointers are pointer-to-volatile.  Sometimes the data type in question is a
"uintN_t" type, sometimes it is a struct covering a range of registers.  There
are other ways to specify fixed addresses, such as using "extern" data that is
defined in a linker file or an assembly file - but I have not seen other
methods used much in recent decades.

The compiler knows nothing about the size of the region pointed to here.  It is
no more appropriate for it to guess the size is 0 than to guess it is 42.  It
should either assume the size is one single object of the named type, or an
array of unknown size of the named type.  (I'd prefer the first, but the second
is also a reasonable choice.)

As an embedded developer, I don't want to have to turn off useful warnings to
avoid false positives on common and essential constructs.

  parent reply	other threads:[~2023-04-24 15:21 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 [this message]
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
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-zfjdAIseJf@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).