rosco-m68k/rosco_m68k

GCC gives false-positive array bounds error

Closed this issue · 0 comments

0xTJ commented

On GCC 12.2.0, I get compile errors -Werror=array-boundswhen dereferencing pointers created from literal constant addresses (like (type *) 0x0000400). This causes building the firmware to fail.

It seems that this is because the compiler treats addresses in the first page of memory as an indexed NULL pointer, which includes the SDB. This gives the diagnostics like the following:

main1.c: In function 'print_cpu_mem_info':
main1.c:120:12: error: array subscript 0 is outside array bounds of 'volatile SystemDataBlock[0]' [-Werror=array-bounds]
  120 |     if (sdb->cpu_model == 0) {

where sdb is defined as:

static volatile SystemDataBlock * const sdb = (volatile SystemDataBlock *)0x400;