public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/106939] New: Linker-defined symbols are stained due to 'array subscript is partly outside array bounds' warning
@ 2022-09-14  5:12 neoxic at icloud dot com
  2022-09-14  5:18 ` [Bug c/106939] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: neoxic at icloud dot com @ 2022-09-14  5:12 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106939
           Summary: Linker-defined symbols are stained due to 'array
                    subscript is partly outside array bounds' warning
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: neoxic at icloud dot com
  Target Milestone: ---

Working with embedded applications, one often deals with manipulating memory
regions via symbols defined in a linker script. Please consider the following
snippet:

-----------------------------------------------------
#include <string.h>

extern char _src, _dst; // Defined by the linker

int main(void) {
    memcpy(&_dst, &_src + 1024, 1111);
    return 0;
}
-----------------------------------------------------

Compilation with GCC 12.2.0 yields lots of warnings:

-----------------------------------------------------
$ cc -O2 -Wall -Wextra -fno-strict-aliasing -fwrapv a.c
a.c: In function ‘main’:
a.c:6:29: warning: array subscript 1024 is outside array bounds of ‘char[1]’
[-Warray-bounds]
    6 |         memcpy(&_dst, &_src + 1024, 1111);
      |                       ~~~~~~^~~~~~
a.c:3:13: note: at offset 1024 into object ‘_src’ of size 1
    3 | extern char _src, _dst; // Defined by the linker
      |             ^~~~
a.c:6:9: warning: ‘memcpy’ forming offset [1, 1110] is out of the bounds [0, 1]
of object ‘_dst’ with type ‘char’ [-Warray-bounds]
    6 |         memcpy(&_dst, &_src + 1024, 1111);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.c:3:19: note: ‘_dst’ declared here
    3 | extern char _src, _dst; // Defined by the linker
      |                   ^~~~
-----------------------------------------------------

These symbols are used as mere address anchors, they don't contain anything.
But no matter what I do like changing their type, casting their addresses, etc,
I can't get rid of the pesky sticky warnings now. Is there a clean way to work
around these warning without turning off Warray-bounds?

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-09-24  1:21 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-14  5:12 [Bug c/106939] New: Linker-defined symbols are stained due to 'array subscript is partly outside array bounds' warning neoxic at icloud dot com
2022-09-14  5:18 ` [Bug c/106939] " pinskia at gcc dot gnu.org
2022-09-14  5:22 ` neoxic at icloud dot com
2022-09-14  5:38 ` pinskia at gcc dot gnu.org
2022-09-14  5:50 ` neoxic at icloud dot com
2022-09-14 16:09 ` pinskia at gcc dot gnu.org
2022-09-14 18:41 ` neoxic at icloud dot com
2022-09-22 19:26 ` jakub at gcc dot gnu.org
2022-09-24  1:21 ` neoxic at icloud dot com

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