public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/105319] New: Unexpected warning with zero-length sized array using -std=gnu99 and -O2
@ 2022-04-20 15:24 piannetta at kalrayinc dot com
  2022-04-21  7:17 ` [Bug c/105319] " rguenth at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: piannetta at kalrayinc dot com @ 2022-04-20 15:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105319
           Summary: Unexpected warning with zero-length sized array using
                    -std=gnu99 and -O2
           Product: gcc
           Version: 10.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: piannetta at kalrayinc dot com
  Target Milestone: ---

// main.c
#define LEN 0

static volatile int tab[LEN];

int main (int argc, char * argv[]) {
        tab[argc] = 0;
}

The code above builds fine with:
  gcc -Wall -std=gnu99
but reports a warning when compiled with -O2:
  gcc -Wall -std=gnu99 -O2
main.c: In function ‘main’:
main.c:4:12: warning: array subscript argc is outside array bounds of ‘volatile
int[0]’ [-Warray-bounds]
    4 |         tab[argc] = 0;
      |         ~~~^~~~~~
main.c:2:21: note: while referencing ‘tab’
    2 | static volatile int tab[LEN];
      |                     ^~~

I've observed this behavior on gcc 10.3.1 and on gcc 12.0.1 (I have not tested
other versions).

I would have expected that the snippet would compile the same way in both cases
and not produce a warning since gnu99 supports zero-length arrays.

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

* [Bug c/105319] Unexpected warning with zero-length sized array using -std=gnu99 and -O2
  2022-04-20 15:24 [Bug c/105319] New: Unexpected warning with zero-length sized array using -std=gnu99 and -O2 piannetta at kalrayinc dot com
@ 2022-04-21  7:17 ` rguenth at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-21  7:17 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
There is no value of argc that is not an out-of-bound access so the warning is
accurate.  Note that array bound diagnostics require -O2.

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

end of thread, other threads:[~2022-04-21  7:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-20 15:24 [Bug c/105319] New: Unexpected warning with zero-length sized array using -std=gnu99 and -O2 piannetta at kalrayinc dot com
2022-04-21  7:17 ` [Bug c/105319] " rguenth 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).