public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/97425] New: bogus array bounds in -Warray-bounds for a function array parameter
@ 2020-10-14 17:22 msebor at gcc dot gnu.org
  2020-10-14 17:46 ` [Bug middle-end/97425] " msebor at gcc dot gnu.org
  2021-09-26  7:54 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-10-14 17:22 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97425
           Summary: bogus array bounds in -Warray-bounds for a function
                    array parameter
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The -Wartray-bounds warnings in the test case below are all expected but the
bounds of the array types referenced in the messages for f3 and and f4 don't
correspond to those in the array parameters.

In f3 the warning should mention ‘int[2][3][4]’ instead and in f4 it should
reference ‘int[1][2][3][4]’.

$ cat z.c && gcc -O2 -S -Wall z.c
void f1 (int a[4])
{
  int *p = &a[0];
  p[4] = 0;
}

void f2 (int a[3][4])
{ 
  int *p = &a[0][0];
  p[3 * 4] = 0;
}

void f3 (int a[2][3][4])
{
  int *p = &a[0][0][0];
  p[2 * 3 * 4] = 0;
}

void f4 (int a[1][2][3][4])
{
  int *p = &a[0][0][0][0];
  p[1 * 2 * 3 * 4] = 0;
}

z.c: In function ‘f1’:
z.c:4:4: warning: array subscript 4 is outside array bounds of ‘int[4]’
[-Warray-bounds]
    4 |   p[4] = 0;
      |   ~^~~
z.c:1:14: note: while referencing ‘a’
    1 | void f1 (int a[4])
      |          ~~~~^~~~
z.c: In function ‘f2’:
z.c:10:4: warning: array subscript 12 is outside array bounds of ‘int[3]’
[-Warray-bounds]
   10 |   p[3 * 4] = 0;
      |   ~^~~~~~~
z.c:7:14: note: while referencing ‘a’
    7 | void f2 (int a[3][4])
      |          ~~~~^~~~~~~
z.c: In function ‘f3’:
z.c:16:4: warning: array subscript 24 is outside array bounds of ‘int[2][4]’
[-Warray-bounds]
   16 |   p[2 * 3 * 4] = 0;
      |   ~^~~~~~~~~~~
z.c:13:14: note: while referencing ‘a’
   13 | void f3 (int a[2][3][4])
      |          ~~~~^~~~~~~~~~
z.c: In function ‘f4’:
z.c:16:16: warning: array subscript 24 is outside array bounds of
‘int[1][3][4]’ [-Warray-bounds]
   16 |   p[2 * 3 * 4] = 0;
      |   ~~~~~~~~~~~~~^~~
z.c:19:14: note: while referencing ‘a’
   19 | void f4 (int a[1][2][3][4])
      |          ~~~~^~~~~~~~~~~~~

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

end of thread, other threads:[~2021-09-26  7:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-14 17:22 [Bug middle-end/97425] New: bogus array bounds in -Warray-bounds for a function array parameter msebor at gcc dot gnu.org
2020-10-14 17:46 ` [Bug middle-end/97425] " msebor at gcc dot gnu.org
2021-09-26  7:54 ` pinskia at gcc dot gnu.org

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