Paul Menzel has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/62828 )
Change subject: x86: mmio: Qualify variables as volatile ......................................................................
x86: mmio: Qualify variables as volatile
GCC 12 warns about out-of-bounds array subscripts:
``` $ make V=1 # emulation/qemu-i440fx […] x86_64-linux-gnu-gcc-12 -MMD -Isrc -Isrc/include -Isrc/commonlib/include -Isrc/commonlib/bsd/include -Ibuild -I3rdparty/vboot/firmware/include -include src/include/kconfig.h -include src/include/rules.h -include src/commonlib/bsd/include/commonlib/bsd/compiler.h -I3rdparty -D__BUILD_DIR__="build" -Isrc/arch/x86/include -D__ARCH_x86_32__ -pipe -g -nostdinc -std=gnu11 -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wno-trigraphs -Wimplicit-fallthrough -Wshadow -Wdate-time -Wtype-limits -Wvla -Wdangling-else -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer -fstrict-aliasing -ffunction-sections -fdata-sections -fno-pie -Wno-packed-not-aligned -fconserve-stack -Wnull-dereference -Wreturn-type -Wlogical-op -Wduplicated-cond -Wno-unused-but-set-variable -Werror -Os -Wno-address-of-packed-member -m32 -Wl,-b,elf32-i386 -Wl,-melf_i386 -m32 -fuse-ld=bfd -fno-stack-protector -Wl,--build-id=none -fno-delete-null-pointer-checks -Wlogical-op -march=i686 -mno-mmx -MT build/bootblock/cpu/x86/lapic/lapic.o -D__BOOTBLOCK__ -c -o build/bootblock/cpu/x86/lapic/lapic.o src/cpu/x86/lapic/lapic.c In file included from src/include/cpu/x86/lapic.h:4, from src/cpu/x86/lapic/lapic.c:5: In function 'read32', inlined from 'xapic_read' at src/include/cpu/x86/lapic.h:13:9, inlined from 'lapic_read' at src/include/cpu/x86/lapic.h:80:10, inlined from 'lapicid' at src/include/cpu/x86/lapic.h:138:21, inlined from 'enable_lapic' at src/cpu/x86/lapic/lapic.c:41:3: src/arch/x86/include/arch/mmio.h:20:16: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 20 | return *((volatile uint32_t *)(addr)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function 'read32', inlined from 'xapic_read' at src/include/cpu/x86/lapic.h:13:9, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:103:11, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:73:2: src/arch/x86/include/arch/mmio.h:20:16: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 20 | return *((volatile uint32_t *)(addr)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function 'write32', inlined from 'xapic_write' at src/include/cpu/x86/lapic.h:18:2, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:106:3, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:73:2: src/arch/x86/include/arch/mmio.h:40:40: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 40 | *((volatile uint32_t *)(addr)) = value; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ In function 'read32', inlined from 'xapic_read' at src/include/cpu/x86/lapic.h:13:9, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:103:11, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:77:2: src/arch/x86/include/arch/mmio.h:20:16: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 20 | return *((volatile uint32_t *)(addr)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function 'write32', inlined from 'xapic_write' at src/include/cpu/x86/lapic.h:18:2, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:106:3, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:77:2: src/arch/x86/include/arch/mmio.h:40:40: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 40 | *((volatile uint32_t *)(addr)) = value; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ In function 'read32', inlined from 'xapic_read' at src/include/cpu/x86/lapic.h:13:9, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:103:11, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:86:3: src/arch/x86/include/arch/mmio.h:20:16: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 20 | return *((volatile uint32_t *)(addr)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function 'write32', inlined from 'xapic_write' at src/include/cpu/x86/lapic.h:18:2, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:106:3, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:86:3: src/arch/x86/include/arch/mmio.h:40:40: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 40 | *((volatile uint32_t *)(addr)) = value; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ In function 'read32', inlined from 'xapic_read' at src/include/cpu/x86/lapic.h:13:9, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:103:11, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:84:3: src/arch/x86/include/arch/mmio.h:20:16: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 20 | return *((volatile uint32_t *)(addr)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function 'write32', inlined from 'xapic_write' at src/include/cpu/x86/lapic.h:18:2, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:106:3, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:84:3: src/arch/x86/include/arch/mmio.h:40:40: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 40 | *((volatile uint32_t *)(addr)) = value; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ In function 'read32', inlined from 'xapic_read' at src/include/cpu/x86/lapic.h:13:9, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:103:11, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:89:2: src/arch/x86/include/arch/mmio.h:20:16: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 20 | return *((volatile uint32_t *)(addr)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function 'write32', inlined from 'xapic_write' at src/include/cpu/x86/lapic.h:18:2, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:106:3, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:89:2: src/arch/x86/include/arch/mmio.h:40:40: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 40 | *((volatile uint32_t *)(addr)) = value; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ cc1: all warnings being treated as errors
```
Fix it, by qualifying the variables as volatile.
Found-by: gcc-12 (Debian 12-20220313-1) 12.0.1 20220314 (experimental) [master r12-7638-g823b3b79cd2] Link: https://mail.coreboot.org/hyperkitty/list/coreboot@coreboot.org/thread/IDX6Q... Solution-by: Nico Huber Change-Id: If2769bb0e365aa9d82d709d3715323819bc9de6e Signed-off-by: Paul Menzel pmenzel@molgen.mpg.de --- M src/arch/x86/include/arch/mmio.h 1 file changed, 8 insertions(+), 8 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/28/62828/1
diff --git a/src/arch/x86/include/arch/mmio.h b/src/arch/x86/include/arch/mmio.h index c2aa0fb..b94b84a 100644 --- a/src/arch/x86/include/arch/mmio.h +++ b/src/arch/x86/include/arch/mmio.h @@ -5,42 +5,42 @@
#include <stdint.h>
-static __always_inline uint8_t read8(const volatile void *addr) +static __always_inline uint8_t read8(const volatile void *volatile addr) { return *((volatile uint8_t *)(addr)); }
-static __always_inline uint16_t read16(const volatile void *addr) +static __always_inline uint16_t read16(const volatile void *volatile addr) { return *((volatile uint16_t *)(addr)); }
-static __always_inline uint32_t read32(const volatile void *addr) +static __always_inline uint32_t read32(const volatile void *volatile addr) { return *((volatile uint32_t *)(addr)); }
-static __always_inline uint64_t read64(const volatile void *addr) +static __always_inline uint64_t read64(const volatile void *volatile addr) { return *((volatile uint64_t *)(addr)); }
-static __always_inline void write8(volatile void *addr, uint8_t value) +static __always_inline void write8(volatile void *volatile addr, uint8_t value) { *((volatile uint8_t *)(addr)) = value; }
-static __always_inline void write16(volatile void *addr, uint16_t value) +static __always_inline void write16(volatile void *volatile addr, uint16_t value) { *((volatile uint16_t *)(addr)) = value; }
-static __always_inline void write32(volatile void *addr, uint32_t value) +static __always_inline void write32(volatile void *volatile addr, uint32_t value) { *((volatile uint32_t *)(addr)) = value; }
-static __always_inline void write64(volatile void *addr, uint64_t value) +static __always_inline void write64(volatile void *volatile addr, uint64_t value) { *((volatile uint64_t *)(addr)) = value; }