public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/94580] missing warning accessing an interior flexible array member
Date: Mon, 13 Apr 2020 17:48:10 +0000	[thread overview]
Message-ID: <bug-94580-4-uBx5XOghy0@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94580-4@http.gcc.gnu.org/bugzilla/>

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Blocks|                            |56456

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
GCC does a little better with zero-length arrays:

$ cat t.c && gcc -O2 -S -Wall -Wextra -o/dev/stdout t.c
struct A { int n, a[0]; };
struct B { struct A a; int x; };

struct B b;

int f0 (void)
{
  b.a.a[1] = 1;
  int t = b.x;
  b.a.a[1] = 0;
  return b.x - t;
}

int f1 (struct B *p)
{
  p->a.a[1] = 1;
  int t = p->x;
  p->a.a[1] = 0;
  return p->x - t;
}

        .file   "t.c"
        .text
t.c: In function ‘f0’:
t.c:10:8: warning: array subscript 1 is above array bounds of ‘int[0]’
[-Warray-bounds]
   10 |   b.a.a[1] = 0;
      |   ~~~~~^~~
t.c:1:19: note: while referencing ‘a’
    1 | struct A { int n, a[0]; };
      |                   ^
        .p2align 4
        .globl  f0
        .type   f0, @function
f0:
.LFB0:
        .cfi_startproc
        movl    $0, b+8(%rip)
        xorl    %eax, %eax
        ret
        .cfi_endproc
.LFE0:
        .size   f0, .-f0
t.c: In function ‘f1’:
t.c:18:9: warning: array subscript 1 is outside the bounds of an interior
zero-length array ‘int[0]’ [-Wzero-length-bounds]
   18 |   p->a.a[1] = 0;
      |   ~~~~~~^~~
t.c:1:19: note: while referencing ‘a’
    1 | struct A { int n, a[0]; };
      |                   ^
        .p2align 4
        .globl  f1
        .type   f1, @function
f1:
.LFB1:
        .cfi_startproc
        movl    $0, 8(%rdi)
        xorl    %eax, %eax
        ret
        .cfi_endproc
.LFE1:
        .size   f1, .-f1
        .globl  b
        .bss
        .align 8
        .type   b, @object
        .size   b, 8
b:
        .zero   8
        .ident  "GCC: (GNU) 10.0.1 20200413 (experimental)"
        .section        .note.GNU-stack,"",@progbits


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56456
[Bug 56456] [meta-bug] bogus/missing -Warray-bounds

      reply	other threads:[~2020-04-13 17:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-13 17:46 [Bug middle-end/94580] New: " msebor at gcc dot gnu.org
2020-04-13 17:48 ` msebor at gcc dot gnu.org [this message]

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-94580-4-uBx5XOghy0@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).