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

Manuel Köppen <manuel.koeppen at gmx dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manuel.koeppen at gmx dot de

--- Comment #2 from Manuel Köppen <manuel.koeppen at gmx dot de> ---
See also here:

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

This is a general problem that was fixed only for avr.
Somehow the first page (that is 4096 bytes) is super-special for the compiler.
Any dereferencing of a pointer pointing to address 1..4095 will create this
warning. You can silence it with

--param=min-pagesize=0

But I don't like, that I now have to add it to every arm microcontroller
firmware CFLAGS.

Here is a very basic example:

int main() {
    return *((int *)4092);
}

Compiling with

arm-none-eabi-gcc -save-temps=cwd -O2 -mcpu=cortex-m4 -Wall -c -o warn.o warn.c

will give you

warn.c: In function 'main':
warn.c:7:12: warning: array subscript 0 is outside array bounds of 'int[0]'
[-Warray-bounds=]
    7 |     return *((int *)4092);
      |            ^~~~~~~~~~~~~~
cc1.exe: note: source object is likely at address zero

If you change 4092 to 0 or any value 4096 or above, the warning will go away.

In most microcontrollers, there is flash at address 0, so the code could make
sense, it is not an academic problem.

I think this should be improved!

Reply via email to