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

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
There is no tail padding at ax2.a + 3, it's just past the end of the the
four-byte object because ax2.a is at offset 1.

-Warray-bounds takes tail padding into consideration by calling
component_ref_size().  That can be seen on a test case like this:

$ cat a.c && gcc -O2 -S -Wall -Wextra a.c
struct Ax { int i; char j, a[]; };

struct Ax ax = { 1, 2, { 3 } };

void f (void)
{
  ax.a[0] = 3;
  ax.a[1] = 2;
  ax.a[2] = 1;
  ax.a[3] = 0;   // -Warray-bounds
}

int g (void)
{
  return __builtin_strlen (&ax.a[3]);   // missing -Warray-bounds
}

a.c: In function ‘f’:
a.c:10:7: warning: array subscript 3 is above array bounds of ‘char[0]’
[-Warray-bounds]
   10 |   ax.a[3] = 0;   // -Warray-bounds
      |   ~~~~^~~
a.c:1:28: note: while referencing ‘a’
    1 | struct Ax { int i; char j, a[]; };
      |                            ^
a.c:3:11: note: defined here ‘ax’
    3 | struct Ax ax = { 1, 2, { 3 } };
      |           ^~

(The reference to 'char[0]' in the warning isn't quite correct: it should be
'char[]'.  This is the subject of pr92326.)

Reply via email to