Dereferencing a constant address pointer when -Warray-bounds is enabled in gcc generates an erroneous warning:
In function 'ppc64_patch_handlers', inlined from 'cpu_970_init' at /root/arch/ppc/qemu/init.c:433:5: /root/arch/ppc/qemu/init.c:400:10: error: array subscript 0 is outside array bounds of 'uint32_t[0]' {aka 'unsigned int[]'} [-Werror=array-bounds] 400 | *dsi = 0x48002002; | ~~~~~^~~~~~~~~~~~ /root/arch/ppc/qemu/init.c:403:10: error: array subscript 0 is outside array bounds of 'uint32_t[0]' {aka 'unsigned int[]'} [-Werror=array-bounds] 403 | *isi = 0x48002202; | ~~~~~^~~~~~~~~~~~ cc1: all warnings being treated as errors make[1]: *** [rules.mak:323: target/arch/ppc/qemu/init.o] Error 1 make[1]: Leaving directory '/root/obj-ppc'
This is a known bug in gcc 12 as described at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523. Work around the bug for now by disabling the warning for ppc64_patch_handlers().
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- arch/ppc/qemu/init.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/arch/ppc/qemu/init.c b/arch/ppc/qemu/init.c index e40385a..253394c 100644 --- a/arch/ppc/qemu/init.c +++ b/arch/ppc/qemu/init.c @@ -390,6 +390,16 @@ cpu_g4_init(const struct cpudef *cpu) /* In order to get 64 bit aware handlers that rescue all our GPRs from getting truncated to 32 bits, we need to patch the existing handlers so they jump to our 64 bit aware ones. */ + +/* + * Disable -Warray-bounds for ppc64_patch_handlers() because accesses + * to low memory locations via constant pointers triggers a warning + * in gcc 12 (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523) + */ + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" + static void ppc64_patch_handlers(void) { @@ -406,6 +416,8 @@ ppc64_patch_handlers(void) asm ("icbi 0, %0" : : "r"(dsi)); asm ("icbi 0, %0" : : "r"(isi)); } + +#pragma GCC diagnostic pop #endif
static void