From 6288da13acb4022897ca2fcf33278cd0e3dabb41 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 29 Sep 2022 11:03:22 -0400 Subject: [PATCH] rp2040: Suppress spurious gcc v12 array bounds warning Signed-off-by: Kevin O'Connor --- src/rp2040/bootrom.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/rp2040/bootrom.c b/src/rp2040/bootrom.c index 99e60f2d..6e6c46e9 100644 --- a/src/rp2040/bootrom.c +++ b/src/rp2040/bootrom.c @@ -15,13 +15,23 @@ // to (especially for the flash functions) call while the XIP layer // is unavailable. +static __always_inline void *rom_hword_as_ptr(uint16_t rom_address) { +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" + return (void *)(uintptr_t)*(uint16_t *)(uintptr_t)rom_address; +#pragma GCC diagnostic pop +#else + return (void *)(uintptr_t)*(uint16_t *)(uintptr_t)rom_address; +#endif +} + static void * _ramfunc rom_func_lookup(uint32_t code) { // Table and lookup function are provided by the BOOTROM - void *(*fn)(uint16_t *, uint32_t) = - (void *)(uintptr_t)(*(uint16_t *)0x18); - uint16_t *table = (uint16_t *)(uintptr_t)(*(uint16_t *)0x14); + void *(*fn)(uint16_t *, uint32_t) = rom_hword_as_ptr(0x18); + uint16_t *table = rom_hword_as_ptr(0x14); return fn(table, code); }