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

David Brown <david at westcontrol dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |david at westcontrol dot com

--- Comment #18 from David Brown <david at westcontrol dot com> ---
This issue does not appear to be related to any particular backend.

Changing the initial code to remove the volatile :

void m(void) {
     uint8_t * ptr2 = ( uint8_t*)(0x0030);
    *ptr2 = 0xd8;
}

gives a warning in gcc 11 as well - "warning: writing 1 byte into a region of
size 0".  (gcc 12 and 13 give the "array subscript [0] is outside array bounds"
warning.)


It is standard practice in embedded development to cast an integer value (often
a compile-time constant, but not always) to a pointer and use that to access
memory-mapped registers or other data at fixed addresses.  Typically the
pointers are pointer-to-volatile.  Sometimes the data type in question is a
"uintN_t" type, sometimes it is a struct covering a range of registers.  There
are other ways to specify fixed addresses, such as using "extern" data that is
defined in a linker file or an assembly file - but I have not seen other
methods used much in recent decades.

The compiler knows nothing about the size of the region pointed to here.  It is
no more appropriate for it to guess the size is 0 than to guess it is 42.  It
should either assume the size is one single object of the named type, or an
array of unknown size of the named type.  (I'd prefer the first, but the second
is also a reasonable choice.)

As an embedded developer, I don't want to have to turn off useful warnings to
avoid false positives on common and essential constructs.

Reply via email to