Bug 104355 - Misleading -Warray-bounds documentation says "always out of bounds"
Summary: Misleading -Warray-bounds documentation says "always out of bounds"
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: 12.0
Assignee: Martin Sebor
URL:
Keywords: diagnostic, documentation, patch
Depends on:
Blocks: Warray-bounds
  Show dependency treegraph
 
Reported: 2022-02-02 20:44 UTC by Jonathan Wakely
Modified: 2024-01-20 17:18 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-02-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2022-02-02 20:44:01 UTC
-Warray-bounds
      -Warray-bounds=n
          This option is only active when -ftree-vrp is active
          (default for -O2 and above). It warns about subscripts
          to arrays that are always out of bounds. This warning
          is enabled by -Wall.

It's not true that it warns for "always out of bounds", as that implies no false positives.
Comment 1 Andrew Pinski 2022-02-02 21:21:23 UTC
Confirmed.
Comment 2 Martin Sebor 2022-02-08 22:17:12 UTC
The documentation is also incorrect about the warning being only active with -ftree-vrp.  A small subset of -Warray-bounds is issued even without optimization.  For example the following warning(s) have been issued since GCC 4.1: 

$ cat a.c && gcc -S -Wall a.c
int f (void)
{
  return __builtin_strlen ("123" + 5);
}
a.c: In function ‘f’:
a.c:3:34: warning: offset ‘5’ outside bounds of constant string [-Warray-bounds]
    3 |   return __builtin_strlen ("123" + 5);
      |                            ~~~~~~^~~
a.c:3:10: warning: offset ‘5’ outside bounds of constant string [-Warray-bounds]
    3 |   return __builtin_strlen ("123" + 5);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Comment 3 Martin Sebor 2022-02-08 22:17:36 UTC
Let me update the manual.
Comment 5 GCC Commits 2022-02-14 22:55:32 UTC
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:7a1b179b08bc802280ca90ed4c6c8d8b25503e66

commit r12-7234-g7a1b179b08bc802280ca90ed4c6c8d8b25503e66
Author: Martin Sebor <msebor@redhat.com>
Date:   Mon Feb 14 15:40:25 2022 -0700

    Update -Warray-bounds documentation [PR104355].
    
    Resolves:
    PR middle-end/104355 - Misleading and outdated -Warray-bounds documentation
    
    gcc/ChangeLog:
            PR middle-end/104355
            * doc/invoke.texi (-Warray-bounds): Update documentation.
Comment 6 sandra 2024-01-19 04:34:50 UTC
Looks like this was fixed by Martin's commit 2 years ago, closing now.