public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/106526] New: array-bounds warning on constant pointer dereferencing
@ 2022-08-04 13:20 wrenger at sra dot uni-hannover.de
  2022-08-04 13:24 ` [Bug c/106526] " wrenger at sra dot uni-hannover.de
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: wrenger at sra dot uni-hannover.de @ 2022-08-04 13:20 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106526
           Summary: array-bounds warning on constant pointer dereferencing
           Product: gcc
           Version: 12.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wrenger at sra dot uni-hannover.de
  Target Milestone: ---

On optimization levels 2 and 3 the GCC frontend emits false array-bounds
warnings when dereferencing constant pointers.

# Example

CFLAGS: -O2 -Wall -Werror

```
int main(void) {
    int ebda = *((int*)(0x40e));
    return ebda;
}
```

The following error only occurs on GCC 12.1 and newer.
```
<source>: In function 'main':
<source>:2:16: error: array subscript 0 is outside array bounds of 'int[0]'
[-Werror=array-bounds]
    2 |     int ebda = *((int*)(0x40e));
      |                ^~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
```

> See: https://godbolt.org/z/Kff744P58

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

* [Bug c/106526] array-bounds warning on constant pointer dereferencing
  2022-08-04 13:20 [Bug c/106526] New: array-bounds warning on constant pointer dereferencing wrenger at sra dot uni-hannover.de
@ 2022-08-04 13:24 ` wrenger at sra dot uni-hannover.de
  2022-08-04 15:12 ` pinskia at gcc dot gnu.org
  2022-08-04 15:38 ` wrenger at sra dot uni-hannover.de
  2 siblings, 0 replies; 4+ messages in thread
From: wrenger at sra dot uni-hannover.de @ 2022-08-04 13:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Lars Wrenger <wrenger at sra dot uni-hannover.de> ---
Same on C++: https://godbolt.org/z/7do3zhavf

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

* [Bug c/106526] array-bounds warning on constant pointer dereferencing
  2022-08-04 13:20 [Bug c/106526] New: array-bounds warning on constant pointer dereferencing wrenger at sra dot uni-hannover.de
  2022-08-04 13:24 ` [Bug c/106526] " wrenger at sra dot uni-hannover.de
@ 2022-08-04 15:12 ` pinskia at gcc dot gnu.org
  2022-08-04 15:38 ` wrenger at sra dot uni-hannover.de
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-08-04 15:12 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is a deliberate change, dup of bug 105762.

If the address is a valid address, you can also pass --param=min-pagesize=0 to
say that all addresses are valid (see PR 99578).

*** This bug has been marked as a duplicate of bug 105762 ***

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

* [Bug c/106526] array-bounds warning on constant pointer dereferencing
  2022-08-04 13:20 [Bug c/106526] New: array-bounds warning on constant pointer dereferencing wrenger at sra dot uni-hannover.de
  2022-08-04 13:24 ` [Bug c/106526] " wrenger at sra dot uni-hannover.de
  2022-08-04 15:12 ` pinskia at gcc dot gnu.org
@ 2022-08-04 15:38 ` wrenger at sra dot uni-hannover.de
  2 siblings, 0 replies; 4+ messages in thread
From: wrenger at sra dot uni-hannover.de @ 2022-08-04 15:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Lars Wrenger <wrenger at sra dot uni-hannover.de> ---
The array-bounds warning itself is nice. In most cases, it is good if the
compiler can find invalid memory accesses.
However, the wording of the warning is confusing. Strictly speaking, we are not
accessing an array (even if *x == x[0]).

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

end of thread, other threads:[~2022-08-04 15:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-04 13:20 [Bug c/106526] New: array-bounds warning on constant pointer dereferencing wrenger at sra dot uni-hannover.de
2022-08-04 13:24 ` [Bug c/106526] " wrenger at sra dot uni-hannover.de
2022-08-04 15:12 ` pinskia at gcc dot gnu.org
2022-08-04 15:38 ` wrenger at sra dot uni-hannover.de

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).