public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/99632] New: missing warning accessing a trailing zero length array member of base class
@ 2021-03-17 18:05 msebor at gcc dot gnu.org
  2021-03-17 18:11 ` [Bug tree-optimization/99632] " pinskia at gcc dot gnu.org
  2021-03-17 19:06 ` msebor at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-03-17 18:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99632
           Summary: missing warning accessing a trailing zero length array
                    member of base class
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

-Warray-bounds triggers for the invalid access in f() and g() but not in h(). 
All three should be diagnosed.  In addition, the warning in g() should be on
the line with the access.

$ cat t.C && gcc -O2 -S -Wall t.C
struct D: B { int j; };

void f (D *p, int i)
{
  p->a[i] = 0;         // -Warray-bounds (good)
}

void g (D *p, int i)
{
  int *q = &p->a[i];   //-Warray-bounds (should be on next line)
  *q = 0; 
}

void h (D *p, int i)
{
  int *q = p->a;
  q[i] = 0;            // missing warning
}


t.C: In function ‘void f(D*, int)’:
t.C:6:9: warning: array subscript i is outside array bounds of ‘int [0]’
[-Warray-bounds]
    6 |   p->a[i] = 0;         // -Warray-bounds (good)
      |   ~~~~~~^
t.C:1:19: note: while referencing ‘B::a’
    1 | struct B { int n, a[0]; };
      |                   ^
t.C: In function ‘void g(D*, int)’:
t.C:11:19: warning: array subscript i is outside array bounds of ‘int [0]’
[-Warray-bounds]
   11 |   int *q = &p->a[i];   //-Warray-bounds (should be on next line)
      |             ~~~~~~^
t.C:1:19: note: while referencing ‘B::a’
    1 | struct B { int n, a[0]; };
      |                   ^

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

* [Bug tree-optimization/99632] missing warning accessing a trailing zero length array member of base class
  2021-03-17 18:05 [Bug tree-optimization/99632] New: missing warning accessing a trailing zero length array member of base class msebor at gcc dot gnu.org
@ 2021-03-17 18:11 ` pinskia at gcc dot gnu.org
  2021-03-17 19:06 ` msebor at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-03-17 18:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The code is chopped off and does not declare the struct B.

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

* [Bug tree-optimization/99632] missing warning accessing a trailing zero length array member of base class
  2021-03-17 18:05 [Bug tree-optimization/99632] New: missing warning accessing a trailing zero length array member of base class msebor at gcc dot gnu.org
  2021-03-17 18:11 ` [Bug tree-optimization/99632] " pinskia at gcc dot gnu.org
@ 2021-03-17 19:06 ` msebor at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-03-17 19:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
The definition missing from comment #0 is:

  struct B { int n, a[0]; };

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

end of thread, other threads:[~2021-03-17 19:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-17 18:05 [Bug tree-optimization/99632] New: missing warning accessing a trailing zero length array member of base class msebor at gcc dot gnu.org
2021-03-17 18:11 ` [Bug tree-optimization/99632] " pinskia at gcc dot gnu.org
2021-03-17 19:06 ` msebor 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).