public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/92326] [10 Regression] wrong bound in zero-length array diagnostics
       [not found] <bug-92326-4@http.gcc.gnu.org/bugzilla/>
@ 2020-04-13 18:39 ` msebor at gcc dot gnu.org
  2020-04-13 21:32 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-04-13 18:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|wrong bound in zero-length  |[10 Regression] wrong bound
                   |array diagnostics           |in zero-length array
                   |                            |diagnostics
           Keywords|                            |patch

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543778.html

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

* [Bug c/92326] [10 Regression] wrong bound in zero-length array diagnostics
       [not found] <bug-92326-4@http.gcc.gnu.org/bugzilla/>
  2020-04-13 18:39 ` [Bug c/92326] [10 Regression] wrong bound in zero-length array diagnostics msebor at gcc dot gnu.org
@ 2020-04-13 21:32 ` cvs-commit at gcc dot gnu.org
  2020-04-13 21:33 ` msebor at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-04-13 21:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:09f041390245da60411a9f0e08c4bedf7430585a

commit r10-7706-g09f041390245da60411a9f0e08c4bedf7430585a
Author: Martin Sebor <msebor@redhat.com>
Date:   Mon Apr 13 15:31:44 2020 -0600

    PR c/92326 - wrong bound in zero-length array diagnostics

    gcc/c-family/ChangeLog:

            PR c/92326
            * c-pretty-print.c (c_pretty_printer::direct_abstract_declarator):
Avoid
            printing array bound for flexible array members.

    gcc/testsuite/ChangeLog:

            PR c/92326
            * c-c++-common/Warray-bounds-8.c: New test.
            * gcc.dg/Warray-bounds-46.c: Adjust expected format of flexible
array
            memebrs in diagnostics.
            * gcc.dg/Warray-bounds-49.c: Same.

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

* [Bug c/92326] [10 Regression] wrong bound in zero-length array diagnostics
       [not found] <bug-92326-4@http.gcc.gnu.org/bugzilla/>
  2020-04-13 18:39 ` [Bug c/92326] [10 Regression] wrong bound in zero-length array diagnostics msebor at gcc dot gnu.org
  2020-04-13 21:32 ` cvs-commit at gcc dot gnu.org
@ 2020-04-13 21:33 ` msebor at gcc dot gnu.org
  2020-04-16  7:43 ` marxin at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-04-13 21:33 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #8 from Martin Sebor <msebor at gcc dot gnu.org> ---
Fixed.

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

* [Bug c/92326] [10 Regression] wrong bound in zero-length array diagnostics
       [not found] <bug-92326-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2020-04-13 21:33 ` msebor at gcc dot gnu.org
@ 2020-04-16  7:43 ` marxin at gcc dot gnu.org
  2020-04-16 23:50 ` msebor at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-04-16  7:43 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |marxin at gcc dot gnu.org
         Resolution|FIXED                       |---
             Status|RESOLVED                    |REOPENED

--- Comment #9 from Martin Liška <marxin at gcc dot gnu.org> ---
The qemu test-case is still reported as warning.
Reduced test-case:

$ cat qemu.i
struct A a;

int c, d;

struct A {
  int scalar;
  int flexible[];
};

void g() {
  a.flexible[c] = d;
}

$ gcc -O2 -c qemu.i -Werror=array-bounds
qemu.i: In function ‘g’:
qemu.i:11:13: error: array subscript <unknown> is outside array bounds of
‘int[]’ [-Werror=array-bounds]
   11 |   a.flexible[c] = d;
      |   ~~~~~~~~~~^~~
qemu.i:7:7: note: while referencing ‘flexible’
    7 |   int flexible[];
      |       ^~~~~~~~
qemu.i:1:10: note: defined here ‘a’
    1 | struct A a;
      |          ^
cc1: some warnings being treated as errors

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

* [Bug c/92326] [10 Regression] wrong bound in zero-length array diagnostics
       [not found] <bug-92326-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2020-04-16  7:43 ` marxin at gcc dot gnu.org
@ 2020-04-16 23:50 ` msebor at gcc dot gnu.org
  2020-04-17  7:35 ` marxin at gcc dot gnu.org
  2020-04-17 15:02 ` msebor at gcc dot gnu.org
  6 siblings, 0 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-04-16 23:50 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|REOPENED                    |RESOLVED

--- Comment #10 from Martin Sebor <msebor at gcc dot gnu.org> ---
This bug isn't about whether or not a warning is issued but about the format of
the flexible array member printed by it: it should be 'int[]' but was 'int[0]'.
 (That's why Jeff and I have been wondering what you meant.)

The warning in the test case in comment #9 is justified: the flexible array has
no elements because struct a is defined but doesn't initialize it with any
(there would be no warning if the struct were only declared but not defined).

Hopefully this test case will explain it:

$ cat pr92326.c && gcc -O2 -S -Wall pr92326.c
struct A a;   // a.flexible has no elements

int c, d;

struct A {
  int scalar;
  int flexible[];
};

void g() {
  a.flexible[c] = d;   // out-of-bounds regardless of c
}

struct A a2 = { 1, { 0 } };   // b.flexible has 1 element

void g2 (void) {
  a2.flexible[c] = d;   // out-of-bounds only if c != 0 (probably should warn)
}

extern struct A a3;  // b.flexible might have one or more elements

void g3 (void) {
  a3.flexible[c] = d;   // unknown if it's in-bounds or out-of-bounds
}

pr92326.c: In function ‘g’:
pr92326.c:11:13: warning: array subscript <unknown> is outside array bounds of
‘int[]’ [-Warray-bounds]
   11 |   a.flexible[c] = d;   // out-of-bounds regardless of c
      |   ~~~~~~~~~~^~~
pr92326.c:7:7: note: while referencing ‘flexible’
    7 |   int flexible[];
      |       ^~~~~~~~
pr92326.c:1:10: note: defined here ‘a’
    1 | struct A a;   // a.flexible has no elements
      |          ^

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

* [Bug c/92326] [10 Regression] wrong bound in zero-length array diagnostics
       [not found] <bug-92326-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2020-04-16 23:50 ` msebor at gcc dot gnu.org
@ 2020-04-17  7:35 ` marxin at gcc dot gnu.org
  2020-04-17 15:02 ` msebor at gcc dot gnu.org
  6 siblings, 0 replies; 7+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-04-17  7:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from Martin Liška <marxin at gcc dot gnu.org> ---
All right, thanks for the clarification. Btw. qemu fixed the warning in the
meantime:
https://github.com/patchew-project/qemu/commit/4ce1e15fbc7266a108a7c77a3962644b3935346e

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

* [Bug c/92326] [10 Regression] wrong bound in zero-length array diagnostics
       [not found] <bug-92326-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2020-04-17  7:35 ` marxin at gcc dot gnu.org
@ 2020-04-17 15:02 ` msebor at gcc dot gnu.org
  6 siblings, 0 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-04-17 15:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from Martin Sebor <msebor at gcc dot gnu.org> ---
Thanks!  I'm glad to see the new warning has helpe identify (and fix) a real
bug!

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

end of thread, other threads:[~2020-04-17 15:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-92326-4@http.gcc.gnu.org/bugzilla/>
2020-04-13 18:39 ` [Bug c/92326] [10 Regression] wrong bound in zero-length array diagnostics msebor at gcc dot gnu.org
2020-04-13 21:32 ` cvs-commit at gcc dot gnu.org
2020-04-13 21:33 ` msebor at gcc dot gnu.org
2020-04-16  7:43 ` marxin at gcc dot gnu.org
2020-04-16 23:50 ` msebor at gcc dot gnu.org
2020-04-17  7:35 ` marxin at gcc dot gnu.org
2020-04-17 15:02 ` 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).